The Point object represents a point in the two dimensional space of the Illustrator document. It is also used to represent two dimensional vector objects.
Constructors
- Parameters:
- x: Number — optional
- y: Number — optional
- Returns:
- Point
Creates a Point object using the width and height values of the given Size object.
Sample code:
// Create a Size with a width of 100pt and a height of 50pt var size = new Size(100, 50); print(size); // prints { width: 100.0, height: 50.0 } var point = new Point(size); print(point); // prints { x: 100.0, y: 50.0 }
- Parameters:
- size: Size
- Returns:
- Point
Operators
Returns the addition of the supplied point to the point as a new point. The object itself is not modified!
Sample code:
var point1 = new Point(5, 10); var point2 = new Point(10, 20); var result = point1 + point2; print(result); // { x: 15.0, y: 30.0 }
- Returns:
- Point — the addition of the two points as a new point
Returns the addition of the supplied value to both coordinates of the point as a new point. The object itself is not modified!
Sample code:
var point = new Point(5, 10); var result = point + 20; print(result); // { x: 25.0, y: 30.0 }
- Returns:
- Point — the addition of the point and the value as a new point
Returns the subtraction of the supplied point from the point as a new point. The object itself is not modified!
Sample code:
var firstPoint = new Point(10, 20); var secondPoint = new Point(5, 5); var result = firstPoint - secondPoint; print(result); // { x: 5.0, y: 15.0 }
- Returns:
- Point — the subtraction of the two points as a new point
Returns the subtraction of the supplied value from both coordinates of the point as a new point. The object itself is not modified!
Sample code:
var point = new Point(10, 20); var result = point - 5; print(result); // { x: 5.0, y: 15.0 }
- Returns:
- Point — the subtraction of the value from the point as a new point
Returns the multiplication of the point with the supplied point as a new point. The object itself is not modified!
Sample code:
var firstPoint = new Point(5, 10); var secondPoint = new Point(4, 2); var result = firstPoint * secondPoint; print(result); // { x: 20.0, y: 20.0 }
- Returns:
- Point — the multiplication of the two points as a new point
Returns the multiplication of the supplied value with both coordinates of the point as a new point. The object itself is not modified!
Sample code:
var point = new Point(10, 20); var result = point * 2; print(result); // { x: 20.0, y: 40.0 }
- Returns:
- Point — the multiplication of the point by the supplied value as a new point
Returns the division of the point by the supplied point as a new point. The object itself is not modified!
Sample code:
var firstPoint = new Point(8, 10); var secondPoint = new Point(2, 5); var result = firstPoint / secondPoint; print(result); // { x: 4.0, y: 2.0 }
- Returns:
- Point — the division of the two points as a new point
Returns the division of both coordinates of the point by the supplied value and returns it as a new point. The object itself is not modified!
Sample code:
var point = new Point(10, 20); var result = point / 2; print(result); // { x: 5.0, y: 10.0 }
- Returns:
- Point — the division of the point by the supplied value as a new point
The modulo operator returns the integer remainders of dividing the point by the supplied point as a new point.
Sample code:
var point = new Point(12, 6); print(point % new Point(5, 2)); // {x: 2, y: 0}
- Returns:
- Point — the integer remainders of dividing the points by each other as a new point
The modulo operator returns the integer remainders of dividing the point by the supplied value as a new point.
Sample code:
var point = new Point(12, 6); print(point % 5); // {x: 2, y: 1}
- Returns:
- Point — the integer remainders of dividing the point by the value as a new point
Properties
The length of the vector that is represented by this point's coordinates. Each point can be interpreted as a vector that points from the origin (x = 0,y = 0) to the point's location. Setting the length changes the location but keeps the vector's angle.
- Returns:
- Number
The vector's angle, measured from the x-axis to the vector.
Angle units are controlled by the script.angleUnits property, and are in degrees by default.
The angle orientation is controlled by the script.coordinateSystem property, which is 'top-down' by default, leading to clockwise angle orientation. In the 'bottom-up' coordinate system, angles are specified in counter-clockwise orientation.
- Returns:
- Number
Functions
Distance & Length
Returns the distance between the point and another point.
Sample code:
var firstPoint = new Point(5, 10); var secondPoint = new Point(5, 20); var distance = firstPoint.getDistance(secondPoint); print(distance); // 10
- Parameters:
- point: Point
- Returns:
- Number
- Parameters:
- length: Number — optional
- Returns:
- Point
Angle & Rotation
Rotates the point around a center point. The object itself is not modified.
Read more about angle units and orientation in the description of the angle property.
- Parameters:
- angle: Number — the rotation angle
- center: Point — the center point of the rotation — optional
- Returns:
- Point — the rotated point
Tests
Checks whether the point is inside the boundaries of the rectangle.
- Parameters:
- rect: Rectangle — the rectangle to check against
- Returns:
- Boolean — true if the point is inside the rectangle, false otherwise
Checks if the point is within a given distance of another point.
- Parameters:
- point: Point — the point to check against
- tolerance: Number — the maximum distance allowed
- Returns:
- Boolean — true if it is within the given distance, false otherwise
Checks if the vector represented by this point is collinear (parallel) to another vector.
- Parameters:
- point: Point — the vector to check against
- Returns:
- Boolean — true if it is parallel, false otherwise
Checks if the vector represented by this point is orthogonal (perpendicular) to another vector.
- Parameters:
- point: Point — the vector to check against
- Returns:
- Boolean — true if it is orthogonal, false otherwise
Checks if this point has both the x and y coordinate set to 0.
- Returns:
- Boolean — true if both x and y are 0, false otherwise
Checks if this point has an undefined value for at least one of its coordinates.
- Returns:
- Boolean — true if either x or y are not a number, false otherwise
Math Functions
Vectorial Math Functions
Returns the dot product of the point and another point.
- Parameters:
- point: Point
- Returns:
- Number — the dot product of the two points
Returns the cross product of the point and another point.
- Parameters:
- point: Point
- Returns:
- Number — the cross product of the two points