Packagecom.yworks.yfiles.geom
Classpublic class YVector
InheritanceYVector Inheritance YObject Inheritance Object

This class represents a vector in the 2-dimensional real vector space. This vector is an ordered 2 tuple and is defined by two doubles.



Public Properties
 PropertyDefined By
  x : Number
[read-only] Returns the first coordinate of the vector.
YVector
  y : Number
[read-only] Returns the second coordinate of the vector.
YVector
Public Methods
 MethodDefined By
  
YVector(dx:Number, dy:Number, init:Boolean = true)
Creates a new vector with given direction.
YVector
  
add(v:YVector):void
Adds a vector to this vector.
YVector
  
[static] Adds the vector to a point and returns the resulting point.
YVector
  
[static] Adds two vectors and returns the result.
YVector
  
angle(v1:YVector, v2:YVector):Number
[static] Returns the angle (measured in radians) between two vectors in clockwise order (with regards to screen coordinates) from v1 to v2.
YVector
 Inherited
equals(o:Object):Boolean
YObject
  
getClass():Class
[override]
YVector
  
[static] Returns this vector with unit length.
YVector
 Inherited
hashCode():int
YObject
  
length():Number
Returns the length of the vector, this is the value of the euclidean norm.
YVector
  
[static] Creates a new vector, whose direction is given by a point.
YVector
  
[static] Creates a new vector which is a copy of another vector.
YVector
  
newYVector3(dx:Number, dy:Number):YVector
[static] Creates a new vector with given direction.
YVector
  
[static] Creates a new vector, whose direction is given by two points.
YVector
  
newYVector5(x1:Number, y1:Number, x2:Number, y2:Number):YVector
[static] Creates a new vector, whose direction is given by two points.
YVector
  
norm():void
Assigns unit length to the vector. Postcondition length() == 1.
YVector
  
[static] Returns the vector which is orthogonal to the given one and has unit length.
YVector
  
rightOf(v1:YVector, v2:YVector):Boolean
[static] Returns true if vector v1 is on the right side of v2.
YVector
  
rotate(angle:Number):YVector
Returns a new YVector instance that is obtained by rotating this vector by the given angle (measured in radians) in clockwise direction (with regards to screen coordinates).
YVector
  
[static] Returns the value of the scalar product of two vectors.
YVector
  
scale(factor:Number):void
Scales the vector by an factor.
YVector
  
toString():String
Returns a string representation of this vector.
YVector
Protected Methods
 MethodDefined By
  
Initializes this object.
YVector
  
Initializes this object.
YVector
  
initYVector3(dx:Number, dy:Number):void
Initializes this object.
YVector
  
Initializes this object.
YVector
  
initYVector5(x1:Number, y1:Number, x2:Number, y2:Number):void
Initializes this object.
YVector
Property Detail
xproperty
x:Number  [read-only]

Returns the first coordinate of the vector.


Implementation
    public function get x():Number
yproperty 
y:Number  [read-only]

Returns the second coordinate of the vector.


Implementation
    public function get y():Number
Constructor Detail
YVector()Constructor
public function YVector(dx:Number, dy:Number, init:Boolean = true)

Creates a new vector with given direction.

Parameters
dx:Number — the first coordinate
 
dy:Number — the second coordinate
 
init:Boolean (default = true) — An internally used switch to help handle proper instance initialization in inheritance chains where classes can have multiple constructor-like factory methods. This parameter can safely be ignored/omitted when calling the constructor.
Method Detail
add()method
public function add(v:YVector):void

Adds a vector to this vector.

Parameters

v:YVector — the vector to add.

addToPoint()method 
public static function addToPoint(p:YPoint, v:YVector):YPoint

Adds the vector to a point and returns the resulting point.

Parameters

p:YPoint — a point.
 
v:YVector — the vector to add to the point.

Returns
YPoint — p+v
addVectors()method 
public static function addVectors(v:YVector, w:YVector):YVector

Adds two vectors and returns the result.

Parameters

v:YVector — first vector to sum.
 
w:YVector — second vector to sum.

Returns
YVector — v+w
angle()method 
public static function angle(v1:YVector, v2:YVector):Number

Returns the angle (measured in radians) between two vectors in clockwise order (with regards to screen coordinates) from v1 to v2. Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom:

 0 --> 1 | v 1 

Parameters

v1:YVector
 
v2:YVector

Returns
Number
getClass()method 
override public function getClass():Class

Returns
Class
getNormal()method 
public static function getNormal(v:YVector):YVector

Returns this vector with unit length.

Parameters

v:YVector

Returns
YVector
initYVector1()method 
protected final function initYVector1(p1:YPoint):void

Initializes this object. See the documentation of the corresponding factory method newYVector1() for details.

Parameters

p1:YPoint

See also

initYVector2()method 
protected final function initYVector2(v:YVector):void

Initializes this object. See the documentation of the corresponding factory method newYVector2() for details.

Parameters

v:YVector

See also

initYVector3()method 
protected final function initYVector3(dx:Number, dy:Number):void

Initializes this object. See the documentation of the corresponding factory method newYVector3() for details.

Parameters

dx:Number
 
dy:Number

See also

initYVector4()method 
protected final function initYVector4(p1:YPoint, p2:YPoint):void

Initializes this object. See the documentation of the corresponding factory method newYVector4() for details.

Parameters

p1:YPoint
 
p2:YPoint

See also

initYVector5()method 
protected final function initYVector5(x1:Number, y1:Number, x2:Number, y2:Number):void

Initializes this object. See the documentation of the corresponding factory method newYVector5() for details.

Parameters

x1:Number
 
y1:Number
 
x2:Number
 
y2:Number

See also

length()method 
public function length():Number

Returns the length of the vector, this is the value of the euclidean norm.

Returns
Number — a value > 0.
newYVector1()method 
public static function newYVector1(p1:YPoint):YVector

Creates a new vector, whose direction is given by a point. The vector is defined by p1 - (0,0).

Parameters

p1:YPoint — the point.

Returns
YVector
newYVector2()method 
public static function newYVector2(v:YVector):YVector

Creates a new vector which is a copy of another vector.

Parameters

v:YVector — the vector, whose values are copied.

Returns
YVector
newYVector3()method 
public static function newYVector3(dx:Number, dy:Number):YVector

Creates a new vector with given direction.

Parameters

dx:Number — the first coordinate
 
dy:Number — the second coordinate

Returns
YVector
newYVector4()method 
public static function newYVector4(p1:YPoint, p2:YPoint):YVector

Creates a new vector, whose direction is given by two points. The vector is defined by p1 - p2.

Parameters

p1:YPoint — the first point.
 
p2:YPoint — the second point.

Returns
YVector
newYVector5()method 
public static function newYVector5(x1:Number, y1:Number, x2:Number, y2:Number):YVector

Creates a new vector, whose direction is given by two points. The vector is defined by (x1 - x2, y1 - y2).

Parameters

x1:Number — the X-coordinate of the first point.
 
y1:Number — the Y-coordinate of the first point.
 
x2:Number — the X-coordinate of the second point.
 
y2:Number — the Y-coordinate of the second point.

Returns
YVector
norm()method 
public function norm():void

Assigns unit length to the vector.

Postcondition length() == 1.

orthoNormal()method 
public static function orthoNormal(v:YVector):YVector

Returns the vector which is orthogonal to the given one and has unit length.

Parameters

v:YVector — a vector.

Returns
YVector — a vector which is orthogonal to v with unit length.
rightOf()method 
public static function rightOf(v1:YVector, v2:YVector):Boolean

Returns true if vector v1 is on the right side of v2.

Parameters

v1:YVector
 
v2:YVector

Returns
Boolean
rotate()method 
public function rotate(angle:Number):YVector

Returns a new YVector instance that is obtained by rotating this vector by the given angle (measured in radians) in clockwise direction (with regards to screen coordinates). Screen coordinates mean positive x-direction is from left to right and positive y-direction is from top to bottom:

 0 --> 1 | v 1 

Parameters

angle:Number — the angle of rotation in radians.

Returns
YVector — the rotated vector.
scalarProduct()method 
public static function scalarProduct(v1:YVector, v2:YVector):Number

Returns the value of the scalar product of two vectors.

Parameters

v1:YVector — the first vector.
 
v2:YVector — the second vector.

Returns
Numberv1.x * v2.x + v1.y * v2.y
scale()method 
public function scale(factor:Number):void

Scales the vector by an factor.

Parameters

factor:Number — the scale factor, with which the length is multiplied.

toString()method 
public function toString():String

Returns a string representation of this vector.

Returns
String