From 5fdb8554aa59432924c6cf2cf4e8c178c5856deb Mon Sep 17 00:00:00 2001 From: student Date: Wed, 11 Apr 2018 17:06:20 -0400 Subject: Update --- CSMath/src/bezier/geom/TDHPoint.java | 85 ++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 CSMath/src/bezier/geom/TDHPoint.java (limited to 'CSMath/src/bezier/geom/TDHPoint.java') diff --git a/CSMath/src/bezier/geom/TDHPoint.java b/CSMath/src/bezier/geom/TDHPoint.java new file mode 100644 index 0000000..40553a9 --- /dev/null +++ b/CSMath/src/bezier/geom/TDHPoint.java @@ -0,0 +1,85 @@ +package bezier.geom; + +/** + * A two-dimensional homogeneous point. + * + * @author bjculkin + * + */ +public class TDHPoint extends TDPoint { + /** + * The homogeneous coordinate for the point. + */ + public final double z; + + /** + * Create a new two-dimensional homogeneous point. + * + * @param x + * The x coordinate. + * @param y + * The y coordinate. + * @param z + * The homogeneous coordinate. + */ + public TDHPoint(double x, double y, double z) { + super(x, y); + + this.z = z; + } + + /** + * Create a new two-dimensional homogeneous point. + * + * The homogeneous coordinate is set to 1. + * + * @param x + * The x coordinate. + * @param y + * The y coordinate. + */ + public TDHPoint(double x, double y) { + this(x, y, 1); + } + + /** + * Convert this point to a plain two-dimensional point. + * + * @return A two-dimensional version of this point. + */ + public TDPoint toTDPoint() { + /* + * Convert back down by dividing each coordinate by the homogeneous value. + */ + return new TDPoint(x / z, y / z); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + long temp; + temp = Double.doubleToLongBits(z); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + TDHPoint other = (TDHPoint) obj; + if (Double.doubleToLongBits(z) != Double.doubleToLongBits(other.z)) + return false; + return true; + } + + @Override + public String toString() { + return "TDHPoint [z=" + z + ", x=" + x + ", y=" + y + "]"; + } +} \ No newline at end of file -- cgit v1.2.3