# Encoding the Intensity and Phase Gradient of Light Beams with Arbitrary Shapes
## 1 Introduction  
Beam shaping is a research field with significant growth over the last forty years [1; 2; 3] with impact in areas such as optical sensing [4; 5], optical communications [6], super-resolution imaging [7; 8], and optical trapping [9; 10; 11]. A vortex beam is a clear example of a beam with a prescribed intensity and phase, in this case the shape is a ring, displaying a spiral phase distribution and zero central light intensity, with a helical phase front carrying orbital angular momentum [11]. For optical trapping, while the intensity gradients of a vortex permit the trapping of a particle, the phase gradients drive it along the trap [12], emphasizing in this manner the importance of manipulating both properties. Moreover, to manipulate multiple micron-sized dielectric particles, it is useful to design light beams with different geometries [9], generating tractor beams through beam shaping techniques. Beam shaping is commonly addressed by truncation of a beam by an aperture, by diffractive elements, such as plates or spatial light modulators (SLM), by refractive elements and by interferometric setups [13]. Given its direct programmability, high spatial resolution, and speed, an SLM offers a dynamic solution for beam shaping, through the generation and display of phase patterns [13]. As stated by [PERSON] et al. [12], beam shaping can be understood as a light drawing tool, allowing many shapes to be represented by knowing in advance the parametric equations that describe them. However, the desired shape may not be a simple or well-known curve; therefore, an analysis of a two-dimensional shape is required first, to determine its parametric equations. Considering an arbitrary shape drawn either by hand or through software, describing a specific trajectory for an optical trapping setup, we propose a method for the generation of such a trajectory with the desired phase gradient. This method for beam shaping receives as input an image of the contour of the desired shape and delivers its corresponding parametric equations. This step of analysis for describing a given trajectory is not commonly studied in beam shaping proposals, where the authors usually focus on generating specific shapes with light [11; 14],on the suitability of the technique for a given application [6; 15; 16; 17; 18; 19; 20] or on the 3D challenge of beam shaping [12]. Approaches for customizing the shape and phase gradient of light beams located in the state of art, are based on caustics [21] or similarly, are based on known parametric curves [12]. Here, we propose a solution to determine the parametric equations of an arbitrary shape handling it as a binary image, computing its Freeman chain code and extracting the harmonic coefficients from the horizontal and vertical waveforms detected. With this information and by analyzing the complex field amplitude of a beam with Gaussian profile along the desired curve, a trajectory and phase can be followed by solving the phase along the horizontal and vertical coordinates previously identified [12]. Displaying the encoded phase over the SLM generates the beam with the designed intensity and phase gradient. Once generated, the detection of these spatial-structured light beams is commonly implemented through an optical trapping setup or within an interference setup [3]. In this work, we implement the detection exploiting the SLM capabilities by encoding a pair of beams in a common path interference setup, to demonstrate that both intensity and phase have been manipulated as intended. In Section 2, our approach for estimating the parametric equations that represent an arbitrary shape is introduced, followed by a detailed description of the experimental setup for generation and detection of the designed beams. In Section 3, we present eight shapes that are analyzed with the proposed algorithm and their intensity images, obtained by adding the effect of a converging lens into the encoded phase.