summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/geom/TDHPoint.java
diff options
context:
space:
mode:
Diffstat (limited to 'CSMath/src/bezier/geom/TDHPoint.java')
-rw-r--r--CSMath/src/bezier/geom/TDHPoint.java85
1 files changed, 85 insertions, 0 deletions
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