Class: Point

graphics.geom. Point


new Point( [x] [, y])

The Point class represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.

The Point class represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The horizontal coordinate of the point.

y number <optional>
0

The vertical coordinate of the point.

Extends

Members


<static> distance

Returns the distance between p1 and p2 the 2 Points reference passed in argument.

Example
var p1 = new Point(10,20) ;var p2 = new Point(40,60) ;trace( Point.distance(p1,p2) ) ; // 50

<static> getMiddle

Returns the middle Point between 2 Points.

Example
var p1 = new Point(10,10) ;var p2 = new Point(20,20) ;var middle = Point.getMiddle(p1,p2) ;trace(middle) ;

<static> interpolate

Determines a point between two specified points.

  • The parameter f determines where the new interpolated point is located relative to the two end points specified by parameters p1 and p2.
  • The closer the value of the parameter f is to 1.0, the closer the interpolated point is to the first point (parameter p1).
  • The closer the value of the parameter f is to 0, the closer the interpolated point is to the second point (parameter p2).
Example
var p1 = new Point(10,10) ;var p2 = new Point(40,40) ;var p3 ;p3 = Point.interpolate( p1 , p2 , 0 ) ;trace(p3) ; // [Point x:40 y:40]p3 = Point.interpolate( p1 , p2 , 1 ) ;trace(p3) ; // [Point x:10 y:10]p3 = Point.interpolate( p1 , p2 , 0.5 ) ;trace(p3) ; // [Point x:25 y:25]

<static> polar

Converts a pair of polar coordinates to a Cartesian point coordinates.

Example
<pre>var polar = Point.polar( 5, Math.atan(3/4) ) ;trace(polar) ; // [Point x:4 y:3]</pre>

angle

The angle value of this Point object.

Example
var p1 = new Point(0,10) ;var p2 = new Point(10,10) ;trace(p1.angle) ; // 90trace(p2.angle) ; // 45

<readonly> length

Indicates the length of the line segment from (0,0) to this point.


x :Number

The horizontal coordinate of the point.

Type:
  • Number
Inherited From:
Default Value:
  • 0

y :Number

The vertical coordinate of the point.

Type:
  • Number
Inherited From:
Default Value:
  • 0

Methods


abs()

Transform the coordinates of this point to used absolute value for the x and y properties.

Example
var p = new Point(-10, -20) ;p.abs() ;trace(p) ; // [Point x:10 y:20]

add(point)

Adds the coordinates of another point to the coordinates of this point.

Parameters:
Name Type Description
point graphics.geom.Point

the point to be added. You can use an object with the properties x and y.


angleBetween(point)

Returns the angle value between this Point object and the specified Point passed in arguments.

Parameters:
Name Type Description
point graphics.geom.Point

The point reference.

Returns:

the angle value between this Point object and the specified Point passed in arguments.

Example
var p1 = new Point(10, 20) ;var p2 = new Point(50, 200) ;var angle = p1.angleBetween(p2) ;

clone()

Returns a shallow copy of the object.

Overrides:
Returns:

a shallow copy of the object.


copyFrom(source)

Copies all of vector data from the source Vector2D object into the calling Vector2D object.

Parameters:
Name Type Description
source graphics.geom.Vector2D

The Vector2D object from which to copy the data.

Inherited From:
Returns:

The current graphics.geom.Vector2D reference.


cross(point)

Returns the cross value of the current Point object with the Point passed in argument.

Parameters:
Name Type Description
point graphics.geom.Point

The Point object use to calculate the cross value.

Returns:

The cross value of the current Point object with the Point passed in argument.

Example
var p1 = new Point(10,20) ;var p2 = new Point(40,60) ;trace(p1.cross(p2)) ; // -200

dot(point)

Returns the dot value of the current Point and the specified Point passed in argument.

Parameters:
Name Type Description
point graphics.geom.Point

The Point to calculate the dot value of the current Point.

Returns:

the dot value of the current Point and the specified Point passed in argument.

Example
var p1 = new Point(10,20) ;var p2 = new Point(40,60) ;trace(p1.dot(p2)) ; // 1600

equals()

Compares the passed-in object with this object for equality.

Inherited From:
Returns:

true if the the specified object is equal with this object.

Type
boolean

getNormal()

Returns the normal value of this Point.

Returns:

the normal value of this Point.

Example
var p = new Point(10,10) ;var n = p.getNormal() ; // [Point x:-10 y:10]trace(n) ;

getProjectionLength(point)

Returns the size of the projection of this Point with an other Point.

Parameters:
Name Type Description
point

the Point use to calculate the length of the projection.

Returns:

the size of the projection of this Point with an other Point.

Example
var p1 = new Point(10,10) ;var p2 = new Point(100,200) ;var size = p1.getProjectionLength(p2) ;trace(size) ; // 0.06

isPerpTo(point)

Returns true if the Point is perpendicular with the passed-in Point.

Parameters:
Name Type Description
point graphics.geom.Point

The Point use to determinate if this Point object is perpendicular.

Returns:

True if the Point is perpendicular with the passed-in Point.

Type
boolean
Example
var p1 = new Point(0,10) ;var p2 = new Point(10,10) ;var p3 = new Point(10,0) ;trace(p1.isPerpTo(p2)) ; // falsetrace(p1.isPerpTo(p3)) ; // true

max(point)

Returns the new Point with the maximum horizontal coordinate and the maximum vertical coordinate.

Parameters:
Name Type Description
point graphics.geom.Point

The Point passed in this method.

Returns:

The new Point with the maximum horizontal coordinate and the maximum vertical coordinate.

Type
graphics.geom.Point
Example
var p1 = new Point(10,100) ;var p2 = new Point(100,10) ;var p3 = p1.max(p2) ;trace(p3) ; // [Point x:100 y:100]

min(point)

Returns a new Point with the minimum horizontal coordinate and the minimize vertical coordinate.

Parameters:
Name Type Description
point graphics.geom.Point

The Point passed in this method

Returns:

A new Point with the min horizontal coordinate and the minimize vertical coordinate.

Type
graphics.geom.Point
Example
var p1 = new Point(10,100) ;var p2 = new Point(100,10) ;var p3 = p1.min(p2) ;trace(p3) ; // [Point x:10 y:10]

negate()

Sets the current Point with negate coordinates.

Example
var p = new Point(10,20) ;trace(p) ; // [Point x:10 y:20]p.negate() ;trace(p) ; // [Point x:-10 y:-20]p.negate() ;trace(p) ; // [Point x:10 y:20]

normalize( [thickness])

Scales the line segment between (0,0) and the current point to a set length.

Parameters:
Name Type Argument Default Description
thickness number <optional>
1

The scaling value. For example, if the current point is (0,5), and you normalize it to 1, the point returned is at (0,1).

See:
Throws:

Error if a zero-length vector or a illegal NaN value is calculate in this method.

Example
var p = new Point(0,5) ;p.normalize() ;trace(p) ; // [Point x:0 y:1]

offset( [dx] [, dy])

Offsets the Point object by the specified amount. The value of dx is added to the original value of x to create the new x value. The value of dy is added to the original value of y to create the new y value.

Parameters:
Name Type Argument Default Description
dx number <optional>
0

The amount by which to offset the horizontal coordinate, x.

dy number <optional>
0

The amount by which to offset the vertical coordinate, y.

Example
var p = new Point(10,10) ;p.offset(10,10) ;trace(p) ; // [Point x:20 y:20]

rotate(angle [, anchor])

Rotates the Point with the specified angle in argument.

Parameters:
Name Type Argument Default Description
angle number

The angle to rotate this Point.

anchor Object <optional>
null

The anchor point to rotate this Point around (by default use the {0,0} position).


scale(value)

Scales the Point with the specified value in argument.

Parameters:
Name Type Description
value number

the value to scale this Point coordinates.


setTo( [x] [, y])

Sets the horizontal and vertical coordinates of this object. If the x and the y parameters are NaN or null the x and y value are 0.

Parameters:
Name Type Argument Default Description
x number <optional>
0

The horizontal coordinate of the point.

y number <optional>
0

The vertical coordinate of the point.

Inherited From:

subtract(point)

Subtracts the coordinates of another point from the coordinates of this point.

Parameters:
Name Type Description
point graphics.geom.Point

The point to be subtracted.


swap(point)

Swap the horizontal and vertical coordinates of two Point objects.

Parameters:
Name Type Description
point graphics.geom.Point

The point to be swap.

Example
var p1 = new Point(10,20) ;var p2 = new Point(30,40) ;trace(p1 + " / " + p2) ; // [Point x:10 y:20] / [Point x:30 y:40]p1.swap(p2) ;trace(p1 + " / " + p2) ; // [Point x:30 y:40] / [Point x:10 y:20]

toObject()

Returns the Object representation of this object.

Inherited From:
Returns:

the Object representation of this object.


toString()

Returns the string representation of this instance.

Overrides:
Returns:

the string representation of this instance.