Packagepegas.geom
Classpublic class Point
InheritancePoint Inheritance Vector2

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 following code creates a point at (0,0) :

  var myPoint:Point = new Point() ; 
  



Public Properties
 PropertyDefined by
  angle : Number
Determinates the angle value of this Point object.
Point
  length : Number
Returns the length of the line segment from (0,0) to this point.
Point
 Inheritedx : Number
Defined the x coordinate.
Vector2
 Inheritedy : Number
Defined the y coordinate.
Vector2
 InheritedZERO : Vector2
[static] Defines the Vector2 object with the x and y properties set to zero.
Vector2
Public Methods
 MethodDefined by
  
Point(... arguments)
Creates a new Point instance.
Point
  
abs():void
Transform the coordinates of this point to used absolute value for the x and y properties.
Point
  
Returns a new Point reference with the absolute value of the coordinates of this Point object.
Point
 Inherited
addition(v:*):void
Computes the addition of two vectors.
Vector2
  
angleBetween(p:Point):Number
Returns the angle value between this Point object and the specified Point passed in arguments.
Point
  
clone():*
Returns the shallow copy of this object.
Point
  
cross(p:Point):Number
Returns the cross value of the current Point object with the Point passed in argument.
Point
  
distance(p1:Point, p2:Point):Number
[static] Returns the distance between p1 and p2 the 2 Points reference passed in argument.
Point
  
dot(p:Point):Number
Returns the dot value of the current Point and the specified Point passed in argument.
Point
  
equals(o:*):Boolean
Compares the specified object with this object for equality.
Point
  
Returns the direction of this Point.
Point
  
getLength():Number
Returns the length of the line segment from (0,0) to this point.
Point
  
[static] Returns the middle Point between 2 Points.
Point
  
Returns the normal value of this Point.
Point
  
Returns the size of the projection of this Point with an other Point.
Point
  
interpolate(p1:Point, p2:Point, f:Number):Point
[static] Determines a point between two specified points.
Point
  
isPerpTo(p:Point):Boolean
Returns true if the Point is perpendicular with the passed-in Point.
Point
  
Returns the new Point with the maximum horizontal coordinate and the maximum vertical coordinate.
Point
  
Returns a new Point with the minimum horizontal coordinate and the minimize vertical coordinate.
Point
  
negate():void
Sets this Point with negate coordinates.
Point
  
Returns the new negate Point of this Point.
Point
  
normalize(thickness:Number):void
Scales the line segment between (0,0) and the current point to a set length.
Point
  
offset(dx:Number, dy:Number):void
Offsets the Point object by the specified amount.
Point
  
plus(p:*):void
Adds the coordinates of another point to the coordinates of this point.
Point
  
plusNew(p:*):Point
Adds the coordinates of another point to the coordinates of this point to create a new point.
Point
  
polar(len:Number, angle:Number):Point
[static] Converts a pair of polar coordinates to a Cartesian point coordinate.
Point
  
Returns the projection of a Point with the specified Point passed in argument.
Point
  
reset(x:Number, y:Number):void
Sets the horizontal and vertical coordinates of this Point.
Point
  
rotate(angle:Number):void
Rotates the Point with the specified angle in argument.
Point
  
rotateNew(angle:Number):Point
Rotates the Point with the specified angle in argument and creates a new Point.
Point
 Inherited
scale(value:Number):void
Scales the vector object with the input value.
Vector2
  
scaleNew(n:Number):Point
Rotates the Point with the specified s value in argument and creates a new Point.
Point
 Inherited
substraction(v:*):void
Computes the substraction of the current vector object with an other.
Vector2
  
Subtracts the coordinates of another point from the coordinates of this point to create a new point.
Point
  
swap(p:Point):void
Swap the horizontal and vertical coordinates of two Point objects.
Point
 Inherited
toFlash():Point
Returns a flash.geom.Point reference of this object.
Vector2
 Inherited
toObject():Object
Returns the Object representation of this object.
Vector2
  
toSource(indent:int = 0):String
Returns a Eden represensation of the object.
Point
 Inherited
toString():String
Returns the string representation of the object.
Vector2
Property detail
angleproperty
angle:Number  [read-write]

Determinates the angle value of this Point object.

Example :

   var p1:Point = new Point(0,10) ;
   var p2:Point = new Point(10,10) ;
   trace(p1.getAngle()) ; // 90
   trace(p2.getAngle()) ; // 45
   
Implementation
    public function get angle():Number
    public function set angle(value:Number):void
lengthproperty 
length:Number  [read-write]

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

Example :

   var p:Point = new Point(0,5) ;
   trace(p.length) ; // 5
   
Implementation
    public function get length():Number
    public function set length(value:Number):void
Constructor detail
Point()constructor
public function Point(... arguments)

Creates a new Point instance.

Parameters

Example :

   import pegas.geom.Point ;
   
   var p1:Point = new Point() ;
   trace(p1) ; // [Point:{0,0}]
   
   var p2:Point = new Point( new Point(25,30) ) ;
   trace(p2) ; // [Point:{25,30}]
   
   var p3:Point = new Point( 25,30 ) ;
   trace(p3) ; // [Point:{25,30}]
   
Parameters
... arguments
Method detail
abs()method
public function abs():void

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

Example :

   var p:Point = new Point(-10, -20) ;
   p.abs() ;
   trace(p) ; // [Point:{10,20}]
   
absNew()method 
public function absNew():Point

Returns a new Point reference with the absolute value of the coordinates of this Point object.

Example :

   var p1:Point = new Point(-10, -20) ;
    var p2:Point = p1.absNew() ;
   trace(p1 + " / " + p2) ; // [Point:{-10,-20}] / [Point:{10,20}]
    

Returns
Point — a new Point reference with the absolute value of the coordinates of this Point object.
angleBetween()method 
public function angleBetween(p:Point):Number

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

Example :

   var p1:Point = new Point(10, 20) ;
   var p2:point = new Point(50, 200) ;
   var angle:Number = p1.angleBetween(p2) ;
   
Parameters
p:Point

Returns
Number — the angle value between this Point object and the specified Point passed in arguments.
clone()method 
public override function clone():*

Returns the shallow copy of this object.

Example :

    var p1:Point = new Point(10, 20) ;
   var p2:point = p1.clone() ;
   

Returns
* — the shallow copy of this object.
cross()method 
public function cross(p:Point):Number

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

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

Parameters
p:Point — The Point object use to calculate the cross value.

Returns
Number — The cross value of the current Point object with the Point passed in argument.
distance()method 
public static function distance(p1:Point, p2:Point):Number

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

Example :

   var p1:Point = new Point(10,20) ;
   var p2:Point = new Point(40,60) ;
   trace( Point.distance(p1,p2) ) ; // 50
   
Parameters
p1:Point — the first Point.
 
p2:Point — the second Point.

Returns
Number — the distance between p1 and p2 the 2 Points reference passed in argument.
dot()method 
public function dot(p:Point):Number

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

Example :

   var p1:Point = new Point(10,20) ;
   var p2:Point = new Point(40,60) ;
   trace(p1.dot(p2)) ; // 1600
   
Parameters
p:Point — the Point to calculate the dot value of the current Point.

Returns
Number — the dot value of the current Point and the specified Point passed in argument.
equals()method 
public override function equals(o:*):Boolean

Compares the specified object with this object for equality.

Example :

   var p1:Point = new Point(10,20) ;
    var p2:Point = new Point(10,20) ;
   var p3:Point = new Point(30,40) ;
    trace(p1.equals(p2)) ; // true
   trace(p1.equals(p3)) ; // false
   
Parameters
o:*

Returns
Booleantrue if the the specified object is equal with this object.
getDirection()method 
public function getDirection():Point

Returns the direction of this Point.

Example :

   var p1 : Point = new Point(10,2);
   var p2 : Point = p1.getDirection();
   trace( p2.getDirection() ) ; 
   

Returns
Point — the direction of this Point.

See also

Point.normalize
getLength()method 
public function getLength():Number

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

Example :

   var p:Point = new Point(0,5) ;
   trace(p.getLength()) ; // 5
   

Returns
Number — the length of the line segment from (0,0) to this point.
getMiddle()method 
public static function getMiddle(p1:Point, p2:Point):Point

Returns the middle Point between 2 Points.

Example :

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

Returns
Point — the middle Point between 2 Points.
getNormal()method 
public function getNormal():Point

Returns the normal value of this Point.

Example :

   var p:Point = new Point(10,10) ;
   var n:Point = p.getNormal() ; // [Point:{-10,10}]
   trace(n) ;
    

Returns
Point — the normal value of this Point.
getProjectionLength()method 
public function getProjectionLength(p:Point):Number

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

Example :

    var p1:Point = new Point(10,10) ;
   var p2:Point = new Point(100,200) ;
   var size:Number = p1.getProjectionLength(p2) ;
   trace(size) ; // 0.06
   
Parameters
p:Point — the Point use to calculate the length of the projection.

Returns
Number — the size of the projection of this Point with an other Point.
interpolate()method 
public static function interpolate(p1:Point, p2:Point, f:Number):Point

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:Point = new Point(10,10) ;
   var p2:Point = new Point(40,40) ;
   var p3:Point ;
   
   p3 = Point.interpolate( p1 , p2, 0 ) ;
   trace(p3) ; // [Point:{40,40}]
   
    p3 = Point.interpolate( p1 , p2, 1 ) ;
   trace(p3) ; // [Point:{10,10}]
   
    p3 = Point.interpolate( p1 , p2, 0.5 ) ;
   trace(p3) ; // [Point:{25,25}]
   
Parameters
p1:Point — The first point.
 
p2:Point — The second Point.
 
f:Number — the The level of interpolation between the two points. Indicates where the new point will be, along the line between p1 and p2. If f=1, pt1 is returned; if f=0, pt2 is returned.

Returns
Point — The new interpolated point.
isPerpTo()method 
public function isPerpTo(p:Point):Boolean

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

Example :

   var p1:Point = new Point(0,10) ;
   var p2:Point = new Point(10,10) ;
   var p3:Point = new Point(10,0) ;
   trace(p1.isPerpTo(p2)) ; // false
   trace(p1.isPerpTo(p3)) ; // true
   
Parameters
p:Point — the Point use to determinate if this Point object is perpendicular.

Returns
Booleantrue if the Point is perpendicular with the passed-in Point.
max()method 
public function max(p:Point):Point

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

Example :

   var p1:Point = new Point(10,100) ;
   var p2:Point = new Point(100,10) ;
   var p3:Point = p1.max(p2) ;
   trace(p3) ; // [Point:{100,100}]
    
Parameters
p:Point — The Point passed in this method

Returns
Point — The new Point with the maximum horizontal coordinate and the maximum vertical coordinate.
min()method 
public function min(p:Point):Point

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

Example :

   var p1:Point = new Point(10,100) ;
   var p2:Point = new Point(100,10) ;
   var p3:Point = p1.min(p2) ;
   trace(p3) ; // [Point:{10,10}]
   
Parameters
p:Point — The Point passed in this method

Returns
Point — a new Point with the min horizontal coordinate and the minimize vertical coordinate.
negate()method 
public function negate():void

Sets this Point with negate coordinates.

Example :

   var p:Point = new Point(10,20) ;
   trace(p) ; // [Point:{10,20}]
   p.negate() ;
   trace(p) ; // [Point:{-10,-20}]
   p.negate() ;
   trace(p) ; // [Point:{10,20}]
   
negateNew()method 
public function negateNew():Point

Returns the new negate Point of this Point.

Example :

   var p:Point = new Point(10,20) ;
   var n:Point = p.negateNew() ;
   trace(n) ; // [Point:{-10,-20}]
   

Returns
Point — The new negate Point of this Point.
normalize()method 
public function normalize(thickness:Number):void

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

Example :

   var p:Point = new Point(0,5) ;
   p.normalize() ;
   trace(p) ; // [Point:{0,1}]
   
Parameters
thickness:Number — 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).

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

See also

length
offset()method 
public function offset(dx:Number, dy:Number):void

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.

Example :

   var p:Point = new Point(10,10) ;
   p.offset(10,10) ;
   trace(p) ; // [Point:{20,20}]
   
Parameters
dx:Number — The amount by which to offset the horizontal coordinate, x.
 
dy:Number — The amount by which to offset the vertical coordinate, y.
plus()method 
public function plus(p:*):void

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

Parameters
p:* — athe point to be added. You can use an object with the properties x and y.
plusNew()method 
public function plusNew(p:*):Point

Adds the coordinates of another point to the coordinates of this point to create a new point.

Parameters
p:* — athe point to be added. You can use an object with the properties x and y.

Returns
Point — The new point.
polar()method 
public static function polar(len:Number, angle:Number):Point

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

Example :

   var polar:Point = Point.polar( 5, Math.atan(3/4) ) ;
   trace(polar) ; // [Point:{4,3}]
   
Parameters
len:Number — The length coordinate of the polar pair.
 
angle:Number — The angle, in radians, of the polar pair.

Returns
Point — The new Cartesian point.
project()method 
public function project(p:Point):Point

Returns the projection of a Point with the specified Point passed in argument.

Parameters
p:Point — the Point to project with this current Point.

Returns
Point — the new project Point.
reset()method 
public function reset(x:Number, y:Number):void

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

Parameters
x:Number
 
y:Number
rotate()method 
public function rotate(angle:Number):void

Rotates the Point with the specified angle in argument.

Parameters
angle:Number — the Angle to rotate this Point.
rotateNew()method 
public function rotateNew(angle:Number):Point

Rotates the Point with the specified angle in argument and creates a new Point.

Parameters
angle:Number — the Angle to rotate this Point.

Returns
Point — The rotate new Point.
scaleNew()method 
public function scaleNew(n:Number):Point

Rotates the Point with the specified s value in argument and creates a new Point.

Parameters
n:Number — the value to scale this Point.

Returns
Point — The scale new Point.
subtractNew()method 
public function subtractNew(p:Point):Point

Subtracts the coordinates of another point from the coordinates of this point to create a new point.

Parameters
p:Point — The point to be subtracted.

Returns
Point — The new Point.
swap()method 
public function swap(p:Point):void

Swap the horizontal and vertical coordinates of two Point objects.

Example :

   var p1:Point = new Point(10,20) ;
   var p2:Point = new Point(30,40) ;
   trace(p1 + " / " + p2) ; // [Point:{10,20}] / [Point:{30,40}]
   p1.swap(p2) ;
   trace(p1 + " / " + p2) ; // [Point:{30,40}] / [Point:{10,20}]
   
Parameters
p:Point
toSource()method 
public override function toSource(indent:int = 0):String

Returns a Eden represensation of the object.

Parameters
indent:int (default = 0)

Returns
String — a string representing the source code of the object.