Class HeadingPoint

java.lang.Object
me.wobblyyyy.pathfinder.geometry.Point
me.wobblyyyy.pathfinder.geometry.HeadingPoint

public class HeadingPoint
extends Point
An extension of the default Point class - this time with z.

For the sake of consistency, every single angle measure in this entire project should be written in degrees. I don't care how you do whatever you do - that's up to you - but all of the angles which I'm using are all written, notated, and stored in degrees.

Due to the nature of inheritance in Java, HeadingPoint can be used as a substitute for just about any situation. If you'd prefer to get an entirely separate point without the z, you can use the static getPoint() method included in this class.

Since:
0.1.0
Author:
Colin Robertson
  • Field Details

    • z

      private final double z
      The point's z.
    • angle

      private final transient Angle angle
      The point's Angle.
  • Constructor Details

    • HeadingPoint

      public HeadingPoint​(double x, double y, double z)
      Create a new z point.

      Because this class extends point, you're still left with a plain old point if you'd like. Actually, I'd suggest that you only use these special z points when absolutely needed - representing the position of a robot, for example.

      Sticking simply with points makes code significantly easier to generify and thus debug. Ultimately, I can't really do much - and I don't really care - what you do, I'm just giving you a suggestion.

      Parameters:
      x - the point's X value.
      y - the point's Y value.
      z - the point's z. All headings, at least all of the headings that I've written, are notated in DEGREES. It would be a FANTASTIC idea to do the same, so you don't end up forgetting and messing something up. Just a suggestion or something.
    • HeadingPoint

      public HeadingPoint​(double x, double y, Angle angle)
      Create a new HeadingPoint.
      Parameters:
      x - the point's X value.
      y - the point's Y value.
      angle - the point's angle.
    • HeadingPoint

      public HeadingPoint​(Point point)
      Create a new HeadingPoint based on a point. Note that this constructor will set the z point's z to 0.
      Parameters:
      point - the point to base the new z point on.
    • HeadingPoint

      public HeadingPoint​(Point point, double z)
      Create a new HeadingPoint based on a point.
      Parameters:
      point - the point that the z point should be based on.
      z - the point's z. All headings, at least all of the headings that I've written, are notated in DEGREES. It would be a FANTASTIC idea to do the same, so you don't end up forgetting and messing something up. Just a suggestion or something.
    • HeadingPoint

      public HeadingPoint​(Point point, Angle angle)
      Create a new HeadingPoint based on a point.
      Parameters:
      point - the point that the z point should be based on.
      angle - the point's z. All headings, at least all of the headings that I've written, are notated in DEGREES. It would be a FANTASTIC idea to do the same, so you don't end up forgetting and messing something up. Just a suggestion or something.
  • Method Details

    • transform

      public HeadingPoint transform​(double deltaX, double deltaY, Angle deltaTheta)
      Create a new HeadingPoint based off the current point and a desired translation.
      Parameters:
      deltaX - the difference in X value.
      deltaY - the difference in Y value.
      deltaTheta - the difference in angle. NOT the current angle, not the new angle - the DIFFERENCE in angle.
      Returns:
      a newly created HeadingPoint based off the calling point and the given delta values.
    • getHeading

      public double getHeading()
      Get the z of the point.
      Returns:
      the point's z.
      See Also:
      getAngle()
    • getAngle

      public Angle getAngle()
      Get the point's angle.
      Returns:
      the point's angle.
      See Also:
      getHeading()
    • getPoint

      public Point getPoint()
      Get a new Point, without the z.
      Returns:
      a new Point, without the z.
    • withNewHeading

      public static HeadingPoint withNewHeading​(Point original, double newHeading)
      Get a HeadingPoint with a new z.
      Parameters:
      original - the original point.
      newHeading - the point's new z.
      Returns:
      a new HeadingPoint with an updated z.
    • blend

      public static HeadingPoint blend​(HeadingPoint a, HeadingPoint b)
      Blend (average) two points together to form another point.
      Parameters:
      a - the first of the two points.
      b - the second of the two points.
      Returns:
      the result blended point.
    • add

      public static HeadingPoint add​(HeadingPoint a, HeadingPoint b)
      Add two points together to form another point.
      Parameters:
      a - one of the two points.
      b - one of the two points.
      Returns:
      the sum of the two points.
    • subtract

      public static HeadingPoint subtract​(HeadingPoint a, HeadingPoint b)
      Subtract the value of point B from point A and get the difference between the two points.
      Parameters:
      a - the first of the two points - this is the point that will be subtracted from.
      b - the second of the two points - this is the point that will get subtracted.
      Returns:
      the difference between the two points.
    • angleOfRad

      public static double angleOfRad​(HeadingPoint a, HeadingPoint b)
      Get the angle from point A to point B. This method inversely subtracts the two points and uses the Math.atan2(double, double) method to determine the angle between them.

      The angle between two points is defined as follows: atan2(y2 - y1, x2 - x1)

      Parameters:
      a - the first of the two points.
      b - the second of the two points.
      Returns:
      the angle between the two points, notated in radians.
    • angleOfDeg

      public static double angleOfDeg​(HeadingPoint a, HeadingPoint b)
      Get the angle from point A to point B. This method inversely subtracts the two points and uses the Math.atan2(double, double) method to determine the angle between them.
      Parameters:
      a - the first of the two points.
      b - the second of the two points.
      Returns:
      the angle between the two points, notated in radians.
    • scale

      public static HeadingPoint scale​(HeadingPoint a, double xMultiplier, double yMultiplier, double headingMultiplier)
      Scale a point (z included) by a certain factor.

      Other lovely scale methods include...

      Parameters:
      a - the point to scale.
      xMultiplier - the multiplier for the point's X value.
      yMultiplier - the multiplier for the point's Y value.
      headingMultiplier - the multiplier for the point's z.
      Returns:
      a newly-scaled point.
    • scale

      public static HeadingPoint scale​(HeadingPoint a, double multiplier)
      Scale a point upwards or downwards by a specific factor.

      This method does not independently scale the X and Y values - to do that, you can take a look at any of these methods:

      Parameters:
      a - the point to be scaled.
      multiplier - the factor to scale the point by.
      Returns:
      a new, scaled, point.
    • scale

      public static HeadingPoint scale​(HeadingPoint a, double xMultiplier, double yMultiplier)
      Scale the X and Y values of a point separately.

      If you're interested in scaling these axes uniformly, you can use the simpler scale(HeadingPoint, double) method.

      Parameters:
      a - the point to be scaled.
      xMultiplier - the value by which the X value is multiplied.
      yMultiplier - the value by which the Y value is multiplier.
      Returns:
      a newly-scaled value.
    • scaleX

      public static HeadingPoint scaleX​(HeadingPoint a, double multiplier)
      Scale only the X value of a point.

      If you'd like to scale both axes at the same time, you can check out either of these two methods.

      Parameters:
      a - the point to be scaled.
      multiplier - the value by which the point should be scaled by.
      Returns:
      a newly-scaled point.
    • scaleY

      public static HeadingPoint scaleY​(HeadingPoint a, double multiplier)
      Scale only the Y value of a point.

      If you'd like to scale both axes at the same time, you can check out either of these two methods.

      Parameters:
      a - the point to be scaled.
      multiplier - the value by which the point should be scaled by.
      Returns:
      a newly-scaled point.
    • average

      public static HeadingPoint average​(HeadingPoint... points)
      Blend several points together.

      There's no weight or bias to this - each of the inputted points is balanced evenly with all of the other points.

      Parameters:
      points - the points to blend together.
      Returns:
      the blended/averaged points.
    • toString

      public java.lang.String toString()
      Get the string value of the point.

      Although Java's default toString method is quite lovely, it doesn't actually do a great job of converting a point to a string. So, all we have to do is override it, and we're all good! Yay!

      Overrides:
      toString in class Point
      Returns:
      the point, expressed as a string.
    • isSame

      public static boolean isSame​(HeadingPoint a, HeadingPoint b)
      Are two z points exactly identical?

      Points are considered to be identical or non-identical based solely on the point's X, Y, and z values. If they're all the same, the points are identical. If they're not, they're not identical.

      Parameters:
      a - the first of the two points.
      b - the second of the two points.
      Returns:
      whether or not the points are identical.