ur_rna.Utilities.geom

## Class Vec2D

- java.lang.Object
- - java.awt.geom.Point2D
  - - java.awt.geom.Point2D.Double
    - - ur_rna.Utilities.geom.Vec2D

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

      public class Vec2D
      extends java.awt.geom.Point2D.Double
      implements java.lang.Cloneable

  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.awt.geom.Point2D

      `java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private static double` | `toStringRoundFactor`
    `static double` | `TwoPI`

    - ### Fields inherited from class java.awt.geom.Point2D.Double

      `x, y`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Vec2D()`
    `Vec2D(double x, double y)`
    `Vec2D(java.awt.geom.Point2D p)`
    `Vec2D(java.awt.geom.Point2D from, java.awt.geom.Point2D to)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Vec2D` | `add(double dx, double dy)`
    `Vec2D` | `add(java.awt.geom.Point2D p)`
    `Vec2D` | `addScaled(java.awt.geom.Point2D p, double scale)`
    `double` | `angleBetween(Vec2D v2)` Gets the smallest angle between two vectors.
    `double` | `angleTo(Vec2D v2)` Gets the full angle from this vector to v2, sweeping counter-clockwise.
    `double` | `arcAngleTo(Vec2D v2, boolean reverse)` This calculates the angle from one vector to another, similar to `angleTo(Vec2D)` except that the output is intended for applications in which the direction of travel is indicated by the sign of the result and the extent of travel is indicated by its absolute value.
    `Vec2D` | `clone()`
    `static double` | `distance(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)` Returns the distance between two points.
    `static double` | `distanceSq(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)` Returns the square of the distance between two points, i.e.
    `double` | `dot(java.awt.geom.Point2D endPoint, java.awt.geom.Point2D referencePoint)`
    `double` | `dot(Vec2D v)`
    `static Vec2D` | `fromAngle(double theta)`
    `Vec2D` | `getAdded(java.awt.geom.Point2D p)`
    `double` | `getAngle()`
    `Vec2D` | `getMidpoint(java.awt.geom.Point2D other)`
    `static Vec2D` | `getMidpoint(java.awt.geom.Point2D start, java.awt.geom.Point2D end)`
    `Vec2D` | `getMultiplied(java.awt.geom.Point2D p)`
    `Vec2D` | `getNegated()`
    `Vec2D` | `getNormalized()`
    `Vec2D` | `getPointAlong(java.awt.geom.Point2D startPoint, double lengthAlongVector)` Returns the location of result to be the point that would be reached by starting at startPoint and traveling along the direction of this vector the distance specified by lengthAlongVector.
    `Vec2D` | `getPointAlongScaled(java.awt.geom.Point2D startPoint, double lengthMultiple)` Sets the location of result to be the point that would be reached by starting at startPoint and traveling along the direction of this vector the specified multiple of this vector's length.
    `static Vec2D` | `getPointBetween(java.awt.geom.Point2D start, java.awt.geom.Point2D end, double fractionOfDistance)`
    `Vec2D` | `getRotated(double theta)` Get a copy of this vector rotated counter-clockwise by the specified angle (in radians)
    `Vec2D` | `getRotated90()` Get a copy of this vector rotated counter-clockwise by 90 degrees
    `Vec2D` | `getScaled(double scale)`
    `Vec2D` | `getScaled(double scaleX, double scaleY)`
    `Vec2D` | `getSubtr(java.awt.geom.Point2D p)`
    `Vec2D` | `getTransformed(java.awt.geom.AffineTransform tr)`
    `double` | `length()` The magnitude (aka Euclidean length) of the vector.
    `double` | `lengthSqr()`
    `static double` | `mod2PI(double angle)` Given any angle in radians, this returns an equivalent angle in the range [0, 2*PI ) Note that 2*PI is an exclusive upper limit (unlike wrapTo2PI).
    `Vec2D` | `multiply(java.awt.geom.Point2D p)`
    `Vec2D` | `negate()`
    `Vec2D` | `normalize()`
    `Vec2D` | `normalize(double x_if_Zero, double y_if_Zero)`
    `Vec2D` | `projectedOn(Vec2D direction)` Calculates the projection of this vector onto the vector specified by direction.
    `static Vec2D` | `reflect(java.awt.geom.Point2D pt, Vec2D reflectionVector, java.awt.geom.Point2D pointOnReflectionLine)`
    `Vec2D` | `rotate(double theta)`
    `Vec2D` | `rotate90()` Rotates this vector 90 degrees counter-clockwise.
    `Vec2D` | `scale(double scale)`
    `Vec2D` | `scale(double scaleX, double scaleY)`
    `Vec2D` | `setLength(double newLength)` Sets the length (magnitude) of this vector.
    `Vec2D` | `setTo(double newX, double newY)` Alias of `Point2D.Double.setLocation(double, double)`
    `Vec2D` | `setTo(java.awt.geom.Point2D p)` Alias of `Point2D.setLocation(Point2D)`
    `Vec2D` | `setTo(Vec2D p)`
    `Vec2D` | `subtr(java.awt.geom.Point2D p)`
    `java.awt.geom.Line2D` | `toLine()` Returns a line starting at (0,0) and ending at the tip of the vector -- (x, y).
    `java.awt.geom.Line2D` | `toLine(java.awt.geom.Point2D start)` Returns a line starting at the given point and ending at the starting point + the vector -- i.e.
    `java.awt.geom.Line2D` | `toLine(java.awt.geom.Point2D start, double distance)` Returns a line starting at the given point, in the direction of the vector, and with the specified distance.
    `java.awt.Point` | `toPoint()`
    `java.awt.geom.Point2D.Float` | `toPointF()`
    `java.lang.String` | `toString()`
    `Vec2D` | `transform(java.awt.geom.AffineTransform tr)`
    `static double` | `wrapTo2PI(double angle)` Given any angle in radians, this returns an equivalent angle in the range [0, 2*PI] In general, multiples of 2*PI map to 0 if they are negative and to 2*PI if they are positive.
    `static double` | `wrapToPI(double angle)` Given any angle in radians, this returns an equivalent angle in the range [-PI, PI] In general, odd multiples of PI map to -PI if they are negative and to PI if they are positive.

    - ### Methods inherited from class java.awt.geom.Point2D.Double

      `getX, getY, setLocation`

    - ### Methods inherited from class java.awt.geom.Point2D

      `distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode, setLocation`

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

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

- - ### Field Detail

    - #### toStringRoundFactor

          private static final double toStringRoundFactor

      See Also:
        Constant Field Values

    - #### TwoPI

          public static final double TwoPI

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Vec2D

          public Vec2D()

    - #### Vec2D

          public Vec2D(double x,
                       double y)

    - #### Vec2D

          public Vec2D(java.awt.geom.Point2D p)

    - #### Vec2D

          public Vec2D(java.awt.geom.Point2D from,
                       java.awt.geom.Point2D to)

  - ### Method Detail

    - #### add

          public Vec2D add(double dx,
                           double dy)

    - #### add

          public Vec2D add(java.awt.geom.Point2D p)

    - #### addScaled

          public Vec2D addScaled(java.awt.geom.Point2D p,
                                 double scale)

    - #### angleBetween

          public double angleBetween(Vec2D v2)

      Gets the smallest angle between two vectors. The result is always between 0 and PI (inclusive). Based on the dot product `A · B = |A| * |B| * cos(θ)`

    - #### angleTo

          public double angleTo(Vec2D v2)

      Gets the full angle from this vector to v2, sweeping counter-clockwise. The result is from -PI to PI. The order of the vectors is important: `v1.angleTo(v2) == -v2.angleTo(v1)`

    - #### arcAngleTo

          public double arcAngleTo(Vec2D v2,
                                   boolean reverse)

      This calculates the angle from one vector to another, similar to `angleTo(Vec2D)` except that the output is intended for applications in which the direction of travel is indicated by the sign of the result and the extent of travel is indicated by its absolute value. Thus instead of returning a value from -PI to PI, this function returns a value from -2PI to 2PI. For example, want to draw an arc from 0 degrees to 270 degrees counter-clockwise. (I.e. the arc should span 3 quadrants.) So v1 = (1, 0) and v2 = (0, -1) But if `angleTo(Vec2D)` were used, it would return -90 degrees, which would result in the arc being drawn CLOCKWISE through only the bottom-right quadrant. This function would return 270 degrees (reverse = false) or -90 (reverse = true); As another example, assume v1 points to (-1, 0) and v2 points to (1, 0). This function would return 180 (reverse = false) or -180 (reverse = true); As another example, assume v1 points to (1, 1) and v2 points to (-1, 1). This function would return 90 (reverse = false) or -270 (reverse = true);
      Parameters:
        `v2` - the other vector
        `reverse` - whether the arc should be drawn counter-clockwise (reverse=false) or clockwise (reverse=true) from v1 to v2. Alternatively reverse=true could be interpreted as "draw the arc counter-clockwise from v2 to v1 instead of from v1 to v2" If reverse is true, the output will be in the range (-360, 0] If reverse is false, the output will be in the range [0, 360)
      Returns:

    - #### clone

          public Vec2D clone()

      Overrides:
        `clone` in class `java.awt.geom.Point2D`

    - #### distance

          public static double distance(java.awt.geom.Point2D p1,
                                        java.awt.geom.Point2D p2)

      Returns the distance between two points.
      Parameters:
        `p1` - one of the points
        `p2` - one of the points
      Returns:
        the distance between the two points

    - #### distanceSq

          public static double distanceSq(java.awt.geom.Point2D p1,
                                          java.awt.geom.Point2D p2)

      Returns the square of the distance between two points, i.e. `(p1.x - p2.x2)^2 + (p1.y - p2.y)^2`
      Parameters:
        `p1` - one of the points
        `p2` - one of the points
      Returns:
        the square of he distance between the two points

    - #### dot

          public double dot(java.awt.geom.Point2D endPoint,
                            java.awt.geom.Point2D referencePoint)

    - #### dot

          public double dot(Vec2D v)

    - #### fromAngle

          public static Vec2D fromAngle(double theta)

    - #### getAdded

          public Vec2D getAdded(java.awt.geom.Point2D p)

    - #### getAngle

          public double getAngle()

    - #### getMidpoint

          public Vec2D getMidpoint(java.awt.geom.Point2D other)

    - #### getMidpoint

          public static Vec2D getMidpoint(java.awt.geom.Point2D start,
                                          java.awt.geom.Point2D end)

    - #### getMultiplied

          public Vec2D getMultiplied(java.awt.geom.Point2D p)

    - #### getNegated

          public Vec2D getNegated()

    - #### getNormalized

          public Vec2D getNormalized()

    - #### getPointAlong

          public Vec2D getPointAlong(java.awt.geom.Point2D startPoint,
                                     double lengthAlongVector)

      Returns the location of result to be the point that would be reached by starting at startPoint and traveling along the direction of this vector the distance specified by lengthAlongVector. (The current length of this vector is irrelevant. I.e. It acts as if it were a unit vector.) This is equivalent to `this.clone().setLength(lengthAlongVector).add(startPoint)`

    - #### getPointAlongScaled

          public Vec2D getPointAlongScaled(java.awt.geom.Point2D startPoint,
                                           double lengthMultiple)

      Sets the location of result to be the point that would be reached by starting at startPoint and traveling along the direction of this vector the specified multiple of this vector's length. This is equivalent to `this.clone().scale(lengthMultiple).add(startPoint)` For example @{code new Vec2D(p1, p2).setPointAlongScaled(p1, 0.5, p3) } would set the point p3 to be the midpoint between p1 and p2.

    - #### getPointBetween

          public static Vec2D getPointBetween(java.awt.geom.Point2D start,
                                              java.awt.geom.Point2D end,
                                              double fractionOfDistance)

    - #### getRotated

          public Vec2D getRotated(double theta)

      Get a copy of this vector rotated counter-clockwise by the specified angle (in radians)

    - #### getRotated90

          public Vec2D getRotated90()

      Get a copy of this vector rotated counter-clockwise by 90 degrees

    - #### getScaled

          public Vec2D getScaled(double scale)

    - #### getScaled

          public Vec2D getScaled(double scaleX,
                                 double scaleY)

    - #### getSubtr

          public Vec2D getSubtr(java.awt.geom.Point2D p)

    - #### getTransformed

          public Vec2D getTransformed(java.awt.geom.AffineTransform tr)

    - #### length

          public double length()

      The magnitude (aka Euclidean length) of the vector.

    - #### lengthSqr

          public double lengthSqr()

    - #### mod2PI

          public static double mod2PI(double angle)

      Given any angle in radians, this returns an equivalent angle in the range [0, 2*PI ) Note that 2*PI is an exclusive upper limit (unlike wrapTo2PI). In general, all multiples of 2*PI map to 0.

    - #### multiply

          public Vec2D multiply(java.awt.geom.Point2D p)

    - #### negate

          public Vec2D negate()

    - #### normalize

          public Vec2D normalize()

    - #### normalize

          public Vec2D normalize(double x_if_Zero,
                                 double y_if_Zero)

    - #### projectedOn

          public Vec2D projectedOn(Vec2D direction)

      Calculates the projection of this vector onto the vector specified by direction. If direction is a unit vector this is equal to `direction * (this·direction)` More generally, this is equal to `direction.normalize().scale(this·direction/direction.length())`

    - #### reflect

          public static Vec2D reflect(java.awt.geom.Point2D pt,
                                      Vec2D reflectionVector,
                                      java.awt.geom.Point2D pointOnReflectionLine)

    - #### rotate

          public Vec2D rotate(double theta)

    - #### rotate90

          public Vec2D rotate90()

      Rotates this vector 90 degrees counter-clockwise. (x is replaced with -y and y is replaced with x). The rotated vector is perpendicular (orthogonal) to its previous state.

    - #### scale

          public Vec2D scale(double scale)

    - #### scale

          public Vec2D scale(double scaleX,
                             double scaleY)

    - #### setLength

          public Vec2D setLength(double newLength)

      Sets the length (magnitude) of this vector. If newLength is negative, the direction of the vector is also reversed. This is equivalent to `normalize()` followed by `scale(double)`

    - #### setTo

          public Vec2D setTo(double newX,
                             double newY)

      Alias of `Point2D.Double.setLocation(double, double)`

    - #### setTo

          public Vec2D setTo(java.awt.geom.Point2D p)

      Alias of `Point2D.setLocation(Point2D)`

    - #### setTo

          public Vec2D setTo(Vec2D p)

    - #### subtr

          public Vec2D subtr(java.awt.geom.Point2D p)

    - #### toLine

          public java.awt.geom.Line2D toLine()

      Returns a line starting at (0,0) and ending at the tip of the vector -- (x, y).

    - #### toLine

          public java.awt.geom.Line2D toLine(java.awt.geom.Point2D start)

      Returns a line starting at the given point and ending at the starting point + the vector -- i.e. (start.x + x, start.y + y).

    - #### toLine

          public java.awt.geom.Line2D toLine(java.awt.geom.Point2D start,
                                             double distance)

      Returns a line starting at the given point, in the direction of the vector, and with the specified distance.

    - #### toPoint

          public java.awt.Point toPoint()

    - #### toPointF

          public java.awt.geom.Point2D.Float toPointF()

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.awt.geom.Point2D.Double`

    - #### transform

          public Vec2D transform(java.awt.geom.AffineTransform tr)

    - #### wrapTo2PI

          public static double wrapTo2PI(double angle)

      Given any angle in radians, this returns an equivalent angle in the range [0, 2*PI] In general, multiples of 2*PI map to 0 if they are negative and to 2*PI if they are positive.

    - #### wrapToPI

          public static double wrapToPI(double angle)

      Given any angle in radians, this returns an equivalent angle in the range [-PI, PI] In general, odd multiples of PI map to -PI if they are negative and to PI if they are positive. (Even multiples of PI, e.g. 2PI, of course, map to 0)