org.eclipse.gef.geometry.euclidean

## Class Vector

- java.lang.Object
- - org.eclipse.gef.geometry.euclidean.Vector

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable

    public class Vector
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable

Represents a `Vector` within 2-dimensional Euclidean space.

See Also:
  Serialized Form

### Field Summary

Fields
`static Vector` `NULL` The (0,0) vector.
`double` `x` The x coordinate of this `Vector`.
`double` `y` The y coordinate of this `Vector`.

### Constructor Summary

Constructors
Constructor and Description
`Vector(double x, double y)` Constructs a `Vector` that points in the specified direction.
`Vector(Point p)` Constructs a `Vector` that is the position `Vector` of the given `Point`.
`Vector(Point start, Point end)` Constructs a `Vector` representing the direction and magnitude between to provided `Point`s.
`Vector(Vector start, Vector end)` Constructs a `Vector` representing the difference between two provided `Vector`s.

### Method Summary

All Methods Instance Methods Concrete Methods
`Vector` `clone()` Clones the given `Vector` using `getCopy()`.
`boolean` `equals(java.lang.Object obj)`
`Vector` `getAdded(Vector other)` Returns a new `Vector` that represents the sum of this `Vector` and the given other `Vector`.
`Angle` `getAngle(Vector other)` Returns the smallest `Angle` between this `Vector` and the provided one.
`Angle` `getAngleCCW(Vector other)` Returns the counter-clockwise (CCW) `Angle` between this `Vector` and the provided one.
`Angle` `getAngleCW(Vector other)` Returns the clockwise (CW) `Angle` between this `Vector` and the provided one.
`Vector` `getAveraged(Vector other)` Creates a new `Vector` which represents the average of this `Vector` with the provided one.
`Vector` `getCopy()` Returns a copy of this `Vector` object.
`double` `getCrossProduct(Vector other)` Calculates the cross product of this `Vector` (lhs) and the given other `Vector` (rhs).
`double` `getDissimilarity(Vector other)` Calculates the magnitude of the cross product of this `Vector` with the given other `Vector`.
`Vector` `getDivided(double factor)` Creates a new `Vector` which represents this `Vector` divided by the provided scalar value.
`double` `getDotProduct(Vector other)` Calculates the dot product of this `Vector` and the given other `Vector`.
`double` `getLength()` Returns the length of this `Vector`.
`Vector` `getMultiplied(double factor)` Creates a new `Vector` which represents this `Vector` multiplied by the provided scalar value.
`Vector` `getNormalized()` Creates a new `Vector` that has the same direction as this `Vector` and a length of 1.
`Vector` `getOrthogonalComplement()` Returns the orthogonal complement of this `Vector`, which is defined to be (-y, x).
`Vector` `getRotatedCCW(Angle angle)` Returns a new `Vector` which corresponds to this `Vector` after rotating it counter-clockwise (CCW) by the given `Angle`.
`Vector` `getRotatedCW(Angle angle)` Returns a new `Vector` which corresponds to this `Vector` after rotating it clockwise (CW) by the given `Angle`.
`double` `getSimilarity(Vector other)` Calculates the similarity of this `Vector` and the provided one.
`Vector` `getSubtracted(Vector other)` Returns a new `Vector` that represents the difference of this `Vector` and the provided one.
`int` `hashCode()`
`boolean` `isHorizontal()` Checks if this `Vector` is horizontal, i.e. whether its horizontal component (the x coordinate) does not equal 0, while its vertical component (the y coordinate) does.
`boolean` `isNull()` Checks if this `Vector`'s x and y coordinates are equal to 0.
`boolean` `isOrthogonalTo(Vector other)` Checks if this `Vector` and the provided one are orthogonal to each other.
`boolean` `isParallelTo(Vector other)` Checks if this `Vector` and the provided one are parallel to each other.
`boolean` `isVertical()` Checks if this `Vector` is vertical, i.e. whether its vertical component (the x coordinate) does not equal 0, while its horizontal component (the y coordinate) does.
`Vector` `rotateCCW(Angle angle)` Rotates this `Vector` counter-clockwise (CCW) by the given `Angle`.
`Vector` `rotateCW(Angle angle)` Rotates this `Vector` clockwise (CW) by the given `Angle`.
`Point` `toPoint()` Returns a `Point` representing this `Vector`.
`java.lang.String` `toString()`

### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`

### Field Detail

#### NULL

    public static final Vector NULL

The (0,0) vector.

#### x

    public double x

The x coordinate of this `Vector`.

#### y

    public double y

The y coordinate of this `Vector`.

### Constructor Detail

#### Vector

    public Vector(double x,
                  double y)

Constructs a `Vector` that points in the specified direction.

Parameters:
  `x` - x coordinate
  `y` - y coordinate

#### Vector

    public Vector(Point p)

Constructs a `Vector` that is the position `Vector` of the given `Point`.

Parameters:
  `p` - the `Point` to construct a position `Vector` for

#### Vector

    public Vector(Point start,
                  Point end)

Constructs a `Vector` representing the direction and magnitude between to provided `Point`s.

Parameters:
  `start` - the start `Point`
  `end` - the end `Point`

#### Vector

    public Vector(Vector start,
                  Vector end)

Constructs a `Vector` representing the difference between two provided `Vector`s.

Parameters:
  `start` - the start `Vector`
  `end` - the end `Vector`

### Method Detail

#### clone

    public Vector clone()

Clones the given `Vector` using `getCopy()`.

Overrides:
  `clone` in class `java.lang.Object`
Returns:
  a copy of this `Vector` object

#### equals

    public boolean equals(java.lang.Object obj)

Overrides:
  `equals` in class `java.lang.Object`
See Also:
  `Object.equals(Object)`

#### getAdded

    public Vector getAdded(Vector other)

Returns a new `Vector` that represents the sum of this `Vector` and the given other `Vector`.

Parameters:
  `other` - the `Vector` that is added to this `Vector`
Returns:
  a new `Vector` representing the sum of this `Vector` and the given other `Vector`

#### getAngle

    public Angle getAngle(Vector other)

Returns the smallest `Angle` between this `Vector` and the provided one.

Parameters:
  `other` - the `Vector` for which the smallest `Angle` to this `Vector` is calculated
Returns:
  the smallest `Angle` between this `Vector` and the provided one

#### getAngleCCW

    public Angle getAngleCCW(Vector other)

Returns the counter-clockwise (CCW) `Angle` between this `Vector` and the provided one.

Parameters:
  `other` - the `Vector` for which the CCW `Angle` to this `Vector` is calculated
Returns:
  the counter-clockwise `Angle` between this `Vector` and the provided one

#### getAngleCW

    public Angle getAngleCW(Vector other)

Returns the clockwise (CW) `Angle` between this `Vector` and the provided one.

Parameters:
  `other` - the `Vector` for which the CW `Angle` to this `Vector` is calculated
Returns:
  the clockwise `Angle` between this `Vector` and the provided one

#### getAveraged

    public Vector getAveraged(Vector other)

Creates a new `Vector` which represents the average of this `Vector` with the provided one.

Parameters:
  `other` - the `Vector` for which the average with this `Vector` is calculated
Returns:
  a new `Vector` which represents the average of this `Vector` and the provided one

#### getCopy

    public Vector getCopy()

Returns a copy of this `Vector` object.

Returns:
  a copy of this `Vector` object

#### getCrossProduct

    public double getCrossProduct(Vector other)

Calculates the cross product of this `Vector` (lhs) and the given other `Vector` (rhs).

Parameters:
  `other` - the rhs `Vector` for which the cross product with this `Vector` is calculated
Returns:
  the cross product of this `Vector` (lhs) and the given other `Vector` (rhs)

#### getDissimilarity

    public double getDissimilarity(Vector other)

Calculates the magnitude of the cross product of this `Vector` with the given other `Vector`. This method normalizes both `Vector`s before calculating the cross product. The resulting dissimilarity value represents the amount by which two `Vector`s are directionally different. For parallel `Vector`s 0 is returned.

Parameters:
  `other` - the `Vector` to compare to this `Vector`
Returns:
  the dissimilarity of both `Vector`s

#### getDivided

    public Vector getDivided(double factor)

Creates a new `Vector` which represents this `Vector` divided by the provided scalar value.

Parameters:
  `factor` - the divisor
Returns:
  a new `Vector` which represents this `Vector` divided by the provided scalar value

#### getDotProduct

    public double getDotProduct(Vector other)

Calculates the dot product of this `Vector` and the given other `Vector`.

Parameters:
  `other` - the `Vector` for which the dot product with this `Vector` is calculated
Returns:
  the dot product of the two `Vector`s

#### getLength

    public double getLength()

Returns the length of this `Vector`.

Returns:
  the length of this `Vector`

#### getMultiplied

    public Vector getMultiplied(double factor)

Creates a new `Vector` which represents this `Vector` multiplied by the provided scalar value.

Parameters:
  `factor` - the scalar multiplication factor to scale this `Vector`
Returns:
  a new `Vector` which represents this `Vector` multiplied by the provided scalar value

#### getNormalized

    public Vector getNormalized()

Creates a new `Vector` that has the same direction as this `Vector` and a length of 1.

Returns:
  a new `Vector` with the same direction as this `Vector` and a length of 1

#### getOrthogonalComplement

    public Vector getOrthogonalComplement()

Returns the orthogonal complement of this `Vector`, which is defined to be (-y, x).

Returns:
  the orthogonal complement of this `Vector`

#### getRotatedCCW

    public Vector getRotatedCCW(Angle angle)

Returns a new `Vector` which corresponds to this `Vector` after rotating it counter-clockwise (CCW) by the given `Angle`.

Parameters:
  `angle` - the rotation `Angle`
Returns:
  a new `Vector` which represents the result of the CCW rotation of this `Vector`

#### getRotatedCW

    public Vector getRotatedCW(Angle angle)

Returns a new `Vector` which corresponds to this `Vector` after rotating it clockwise (CW) by the given `Angle`.

Parameters:
  `angle` - the rotation `Angle`
Returns:
  a new `Vector` which represents the result of the CW rotation of this `Vector`

#### getSimilarity

    public double getSimilarity(Vector other)

Calculates the similarity of this `Vector` and the provided one. The similarity is defined as the absolute value of the dotProduct(). For orthogonal `Vector`s, 0 is returned.

Parameters:
  `other` - the `Vector` for which the similarity to this `Vector` is calculated
Returns:
  the similarity of this `Vector` and the provided one
See Also:
  `getDissimilarity(Vector)`

#### getSubtracted

    public Vector getSubtracted(Vector other)

Returns a new `Vector` that represents the difference of this `Vector` and the provided one.

Parameters:
  `other` - the `Vector` that is subtracted from this `Vector`
Returns:
  a new `Vector` representing the difference of this `Vector` and the provided one

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `java.lang.Object`
See Also:
  `Object.hashCode()`

#### isHorizontal

    public boolean isHorizontal()

Checks if this `Vector` is horizontal, i.e. whether its horizontal component (the x coordinate) does not equal 0, while its vertical component (the y coordinate) does.

Returns:
  `true` if this `Vector`'s x coordinate does not equal 0 and this `Vector`'s y coordinate does equal 0, otherwise `false`

#### isNull

    public boolean isNull()

Checks if this `Vector`'s x and y coordinates are equal to 0.

Returns:
  `true` if this `Vector`'s x and y coordinates are equal to 0, otherwise `false`

#### isOrthogonalTo

    public boolean isOrthogonalTo(Vector other)

Checks if this `Vector` and the provided one are orthogonal to each other.

Parameters:
  `other` - the `Vector` which is checked for orthogonality to this `Vector`
Returns:
  `true` if this `Vector` and the provided one are orthogonal to each other, otherwise `false`

#### isParallelTo

    public boolean isParallelTo(Vector other)

Checks if this `Vector` and the provided one are parallel to each other.

Parameters:
  `other` - the `Vector` that is checked to be parallel to this `Vector`
Returns:
  `true` if this `Vector` and the provided one are parallel, otherwise `false`

#### isVertical

    public boolean isVertical()

Checks if this `Vector` is vertical, i.e. whether its vertical component (the x coordinate) does not equal 0, while its horizontal component (the y coordinate) does.

Returns:
  `true` if this `Vector`'s y coordinate does not equal 0 and this `Vector`'s x coordinate does equal 0,

#### rotateCCW

    public Vector rotateCCW(Angle angle)

Rotates this `Vector` counter-clockwise (CCW) by the given `Angle`.

Parameters:
  `angle` - the rotation `Angle`
Returns:
  `this` for convenience

#### rotateCW

    public Vector rotateCW(Angle angle)

Rotates this `Vector` clockwise (CW) by the given `Angle`.

Parameters:
  `angle` - the rotation `Angle`
Returns:
  `this` for convenience

#### toPoint

    public Point toPoint()

Returns a `Point` representing this `Vector`.

Returns:
  a `Point` representing this `Vector`

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`
See Also:
  `Object.toString()`