Class HeadingPoint
public class HeadingPoint extends Point
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 Summary
-
Constructor Summary
Constructors Constructor Description HeadingPoint(double x, double y, double z)
Create a new z point.HeadingPoint(double x, double y, Angle angle)
Create a newHeadingPoint
.HeadingPoint(Point point)
Create a new HeadingPoint based on a point.HeadingPoint(Point point, double z)
Create a new HeadingPoint based on a point.HeadingPoint(Point point, Angle angle)
Create a new HeadingPoint based on a point. -
Method Summary
Modifier and Type Method Description static HeadingPoint
add(HeadingPoint a, HeadingPoint b)
Add two points together to form another point.static double
angleOfDeg(HeadingPoint a, HeadingPoint b)
Get the angle from point A to point B.static double
angleOfRad(HeadingPoint a, HeadingPoint b)
Get the angle from point A to point B.static HeadingPoint
average(HeadingPoint... points)
Blend several points together.static HeadingPoint
blend(HeadingPoint a, HeadingPoint b)
Blend (average) two points together to form another point.Angle
getAngle()
Get the point's angle.double
getHeading()
Get the z of the point.Point
getPoint()
Get a new Point, without the z.static boolean
isSame(HeadingPoint a, HeadingPoint b)
Are two z points exactly identical?static HeadingPoint
scale(HeadingPoint a, double multiplier)
Scale a point upwards or downwards by a specific factor.static HeadingPoint
scale(HeadingPoint a, double xMultiplier, double yMultiplier)
Scale the X and Y values of a point separately.static HeadingPoint
scale(HeadingPoint a, double xMultiplier, double yMultiplier, double headingMultiplier)
Scale a point (z included) by a certain factor.static HeadingPoint
scaleX(HeadingPoint a, double multiplier)
Scale only the X value of a point.static HeadingPoint
scaleY(HeadingPoint a, double multiplier)
Scale only the Y value of a point.static HeadingPoint
subtract(HeadingPoint a, HeadingPoint b)
Subtract the value of pointB
from pointA
and get the difference between the two points.java.lang.String
toString()
Get the string value of the point.HeadingPoint
transform(double deltaX, double deltaY, Angle deltaTheta)
Create a newHeadingPoint
based off the current point and a desired translation.static HeadingPoint
withNewHeading(Point original, double newHeading)
Get a HeadingPoint with a new z.Methods inherited from class me.wobblyyyy.pathfinder.geometry.Point
add, average, blend, copy, getTheta, getX, getY, isSame, scale, scale, scale, scale, scaleX, scaleY, withHeading, withHeading, withHeading
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
z
private final double zThe point's z. -
angle
The point'sAngle
.
-
-
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
Create a newHeadingPoint
.- Parameters:
x
- the point's X value.y
- the point's Y value.angle
- the point's angle.
-
HeadingPoint
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
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
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
Create a newHeadingPoint
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
Get the point's angle.- Returns:
- the point's angle.
- See Also:
getHeading()
-
getPoint
Get a new Point, without the z.- Returns:
- a new Point, without the z.
-
withNewHeading
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
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
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
Subtract the value of pointB
from pointA
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
Get the angle from point A to point B. This method inversely subtracts the two points and uses theMath.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
Get the angle from point A to point B. This method inversely subtracts the two points and uses theMath.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...
-
Scale only X:
scaleX(HeadingPoint, double)
-
Scale only Y:
scaleY(HeadingPoint, double)
-
Scale both:
scale(HeadingPoint, double, double)
-
Scale both by the same factor:
scale(HeadingPoint, double)
- 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 only X:
-
scale
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:
- Scale only X:
scaleX(HeadingPoint, double)
- Scale only Y:
scaleY(HeadingPoint, double)
- Scale both:
scale(HeadingPoint, double, double)
- Parameters:
a
- the point to be scaled.multiplier
- the factor to scale the point by.- Returns:
- a new, scaled, point.
- Scale only X:
-
scale
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
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.
- X and Y together:
scale(HeadingPoint, double)
- X and Y separate:
scale(HeadingPoint, double, double)
- Parameters:
a
- the point to be scaled.multiplier
- the value by which the point should be scaled by.- Returns:
- a newly-scaled point.
- X and Y together:
-
scaleY
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.
- X and Y together:
scale(HeadingPoint, double)
- X and Y separate:
scale(HeadingPoint, double, double)
- Parameters:
a
- the point to be scaled.multiplier
- the value by which the point should be scaled by.- Returns:
- a newly-scaled point.
- X and Y together:
-
average
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!
-
isSame
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.
-