Sg 2.9
Point
Packages RSS
About
News
Gallery
Scripts
Tutorials
Download
Reference
Forum
Users
License
Twitter

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

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

Creates a Point object using the coordinates of the given Point object.

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

Checks whether the coordinates of the point are equal to that of the supplied point.

Sample code:

var point = new Point(5, 10);
print(point == new Point(5, 10)); // true
print(point == new Point(1, 1)); // false
print(point != new Point(1, 1)); // true
    Returns:
  • Boolean

Properties

x

The x coordinate of the point

    Returns:
  • Number
y

The y coordinate of the point

    Returns:
  • Number

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

This property is only present if the point is an anchor or control point of a Segment or a Curve. In this case, it returns true if it is selected by the user, false otherwise

    Returns:
  • Boolean

Read-only.

    Returns:
  • Number

Functions

Returns a copy of the point. This is useful as the following code only generates a flat copy:

var point1 = new Point();
var point2 = point1;
point2.x = 1; // also changes point1.x
var point2 = point1.clone();
point2.x = 1; // doesn't change point1.x
    Returns:
  • Point — the cloned point

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
    Returns:
  • Number
    Parameters:
  • length: Number — optional

Angle & Rotation

Returns the smaller angle between two vectors. The angle is unsigned, no information about rotational direction is given.

Read more about angle units and orientation in the description of the angle property.

    Returns:
  • Number

Returns the angle between two vectors. The angle is directional and signed, giving information about the rotational direction.

Read more about angle units and orientation in the description of the angle property.

    Returns:
  • Number

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:
  • Booleantrue 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:
  • Booleantrue 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:
  • Booleantrue 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:
  • Booleantrue if it is orthogonal, false otherwise

Checks if this point has both the x and y coordinate set to 0.

    Returns:
  • Booleantrue 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:
  • Booleantrue if either x or y are not a number, false otherwise

Math Functions

Returns a new point with rounded x and y values. The object itself is not modified!

Sample code:

var point = new Point(10.2, 10.9);
var roundPoint = point.round();
print(roundPoint); // { x: 10.0, y: 11.0 }

Returns a new point with the nearest greater non-fractional values to the specified x and y values. The object itself is not modified!

Sample code:

var point = new Point(10.2, 10.9);
var ceilPoint = point.ceil();
print(ceilPoint); // { x: 11.0, y: 11.0 }

Returns a new point with the nearest smaller non-fractional values to the specified x and y values. The object itself is not modified!

Sample code:

var point = new Point(10.2, 10.9);
var floorPoint = point.floor();
print(floorPoint); // { x: 10.0, y: 10.0 }

Returns a new point with the absolute values of the specified x and y values. The object itself is not modified!

Sample code:

var point = new Point(-5, 10);
var absPoint = point.abs();
print(absPoint); // { x: 5.0, y: 10.0 }

Vectorial Math Functions

Returns the dot product of the point and another point.

    Returns:
  • Number — the dot product of the two points

Returns the cross product of the point and another point.

    Returns:
  • Number — the cross product of the two points

Returns the projection of the point on another point. Both points are interpreted as vectors.

    Returns:
  • Point — the project of the point on another point

Static Functions

Returns a new point object with the smallest x and y of the supplied points.

Sample code:

var point1 = new Point(10, 100);
var point2 = new Point(200, 5);
var minPoint = Point.min(point1, point2);
print(minPoint); // { x: 10.0, y: 5.0 }
    Returns:
  • Point — The newly created point object

Returns a new point object with the largest x and y of the supplied points.

Sample code:

var point1 = new Point(10, 100);
var point2 = new Point(200, 5);
var maxPoint = Point.max(point1, point2);
print(maxPoint); // { x: 200.0, y: 100.0 }
    Returns:
  • Point — The newly created point object

Returns a point object with random x and y values between 0 and 1.

Sample code:

var maxPoint = new Point(100, 100);
var randomPoint = Point.random();
// A point between {x:0, y:0} and {x:100, y:100}:
var point = maxPoint * randomPoint;

AltStyle によって変換されたページ (->オリジナル) /