diff options
32 files changed, 305 insertions, 781 deletions
diff --git a/CSMath/src/bezier/BezierPanel.java b/CSMath/src/bezier/BezierPanel.java index 529612a..6e605c9 100644 --- a/CSMath/src/bezier/BezierPanel.java +++ b/CSMath/src/bezier/BezierPanel.java @@ -17,14 +17,20 @@ import bezier.geom.transform.TDHTransform; import bezier.geom.transform.TDHTranslate;
import bezier.geom.transform.TDHXAxisReflection;
-/*
+/**
* Panel that graphs a set of bezier curves.
*/
public class BezierPanel extends JPanel {
+ /**
+ * The collection of curves to graph.
+ */
public final Collection<Bezier> curves;
private static final long serialVersionUID = 8748298173487657108L;
+ /**
+ * Create a new bezier panel.
+ */
public BezierPanel() {
super();
@@ -33,6 +39,10 @@ public class BezierPanel extends JPanel { setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
}
+ /**
+ * Create a new bezier panel with a specific set of curves.
+ * @param curvs The curves to graph.
+ */
public BezierPanel(Collection<Bezier> curvs) {
super();
diff --git a/CSMath/src/bezier/ColorInputPanel.java b/CSMath/src/bezier/ColorInputPanel.java index 10cb843..8d8d5ba 100644 --- a/CSMath/src/bezier/ColorInputPanel.java +++ b/CSMath/src/bezier/ColorInputPanel.java @@ -7,18 +7,30 @@ import javax.swing.JColorChooser; import javax.swing.JLabel;
import javax.swing.JPanel;
-/*
+/**
* Panel for inputting colors.
*/
public class ColorInputPanel extends JPanel {
private static final long serialVersionUID = 5201595672794938745L;
+ /**
+ * The color picker being used.
+ */
public final JColorChooser picker;
+ /**
+ * Create a color picker.
+ * @param label The label for the color.
+ */
public ColorInputPanel(String label) {
this(Color.WHITE, label);
}
+ /**
+ * Create a color picker.
+ * @param init The initial color to use.
+ * @param label The label for the color.
+ */
public ColorInputPanel(Color init, String label) {
picker = new JColorChooser(init);
diff --git a/CSMath/src/bezier/CulkinAsssignmentNine.java b/CSMath/src/bezier/CulkinAsssignmentNine.java index 120b507..f19c5e2 100644 --- a/CSMath/src/bezier/CulkinAsssignmentNine.java +++ b/CSMath/src/bezier/CulkinAsssignmentNine.java @@ -55,6 +55,10 @@ public class CulkinAsssignmentNine { curveDirectory.put("Default", currentCurve.getVal());
}
+ /**
+ * Main method.
+ * @param args Unused CLI args.
+ */
public static void main(String[] args) {
CulkinAsssignmentNine assign = new CulkinAsssignmentNine();
diff --git a/CSMath/src/bezier/CurveEditor.java b/CSMath/src/bezier/CurveEditor.java index 70f1352..1d683f8 100644 --- a/CSMath/src/bezier/CurveEditor.java +++ b/CSMath/src/bezier/CurveEditor.java @@ -16,7 +16,7 @@ import javax.swing.border.TitledBorder; import bezier.geom.Bezier;
-/*
+/**
* Do editing of curve properties.
*/
public class CurveEditor implements ActionListener {
@@ -24,6 +24,12 @@ public class CurveEditor implements ActionListener { private JFrame fram;
private BezierPanel canvas;
+ /**
+ * Create a new curve property editor.
+ * @param fram The frame we came from.
+ * @param currentCurve The curve being edited.
+ * @param canvas The panel the curve is being drawn on.
+ */
public CurveEditor(JFrame fram, Holder<Bezier> currentCurve, BezierPanel canvas) {
this.fram = fram;
this.canvas = canvas;
diff --git a/CSMath/src/bezier/PointAdder.java b/CSMath/src/bezier/PointAdder.java index 8866217..34f0667 100644 --- a/CSMath/src/bezier/PointAdder.java +++ b/CSMath/src/bezier/PointAdder.java @@ -22,10 +22,10 @@ import bezier.geom.TDPoint; *
*/
public class PointAdder implements ActionListener {
- private final DefaultListModel<TDPoint> pointModel;
+ final DefaultListModel<TDPoint> pointModel;
private final JFrame fram;
- private Bezier curve;
+ Bezier curve;
/**
* Create a listener that adds points to a bezier curve.
diff --git a/CSMath/src/bezier/geom/Bezier.java b/CSMath/src/bezier/geom/Bezier.java index dbc6a12..0a70db3 100644 --- a/CSMath/src/bezier/geom/Bezier.java +++ b/CSMath/src/bezier/geom/Bezier.java @@ -24,7 +24,7 @@ public class Bezier { * Create a new bezier curve from a set of control points.
*
* @param points
- * The control points to use.
+ * The control points to use.
*/
public Bezier(TDPoint... points) {
data = new BezierProperties();
@@ -40,7 +40,7 @@ public class Bezier { * Do a scaled evaluation of the curve.
*
* @param t
- * The value to evaluate at.
+ * The value to evaluate at.
* @return The point on the curve, scaled by the curves scaling factor.
*/
public TDPoint scaleEval(double t) {
@@ -51,11 +51,11 @@ public class Bezier { * Do a scaled evaluation of the curve.
*
* @param t
- * The value to evaluate at.
+ * The value to evaluate at.
+ * @return The point on the curve.
*/
public TDPoint eval(double t) {
- if (controls.isEmpty())
- return new TDPoint(0, 0);
+ if (controls.isEmpty()) return new TDPoint(0, 0);
TDPoint punkt = evalIntern(t, controls.size() - 1, 0);
@@ -95,7 +95,7 @@ public class Bezier { * Split a curve into two curves at a specific point.
*
* @param t
- * The point to split the curve at.
+ * The point to split the curve at.
* @return The two curves, split at that point.
*/
public Bezier[] decompose(double t) {
@@ -136,10 +136,11 @@ public class Bezier { }
/**
- * Get the bounding box for a transformed version of this curves control points.
+ * Get the bounding box for a transformed version of this curves control
+ * points.
*
* @param transform
- * The transform to apply to the control points.
+ * The transform to apply to the control points.
* @return The bounding box for the transformed control points.
*/
public TDPoint[] extrema(TDHTransform transform) {
@@ -197,18 +198,13 @@ public class Bezier { @Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
Bezier other = (Bezier) obj;
if (controls == null) {
- if (other.controls != null)
- return false;
- } else if (!controls.equals(other.controls))
- return false;
+ if (other.controls != null) return false;
+ } else if (!controls.equals(other.controls)) return false;
return true;
}
diff --git a/CSMath/src/bezier/geom/BezierProperties.java b/CSMath/src/bezier/geom/BezierProperties.java index 1b5443d..d73c1f1 100644 --- a/CSMath/src/bezier/geom/BezierProperties.java +++ b/CSMath/src/bezier/geom/BezierProperties.java @@ -2,6 +2,12 @@ package bezier.geom; import java.awt.Color;
+/**
+ * Properties for graphing a bezier curve.
+ *
+ * @author bjculkin
+ *
+ */
public class BezierProperties {
/**
* The number of separate points to graph from the curve.
@@ -14,15 +20,38 @@ public class BezierProperties { public double scale = 5;
/**
- * The colors for varying parts of the curve.
+ * The color for the curve itself.
*/
- public Color curveColor = Color.BLACK;
- public Color pointColor = Color.RED;
- public Color boxColor = Color.GREEN;
+ public Color curveColor = Color.BLACK;
+ /**
+ * The color for the points in the curve.
+ */
+ public Color pointColor = Color.RED;
+ /**
+ * The color for the bounding box.
+ */
+ public Color boxColor = Color.GREEN;
+ /**
+ * Create a new set of default bezier properties.
+ */
public BezierProperties() {
}
+ /**
+ * Create a new set of bezier properties, with specific values.
+ *
+ * @param parts
+ * The number of points to graph in the curve.
+ * @param scale
+ * The amount to scale the curve by.
+ * @param curveColor
+ * The color for the curve.
+ * @param pointColor
+ * The color for the points in the curve.
+ * @param boxColor
+ * The color for the bounding box of the curve.
+ */
public BezierProperties(int parts, double scale, Color curveColor, Color pointColor, Color boxColor) {
this.parts = parts;
this.scale = scale;
@@ -47,38 +76,27 @@ public class BezierProperties { @Override
public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (getClass() != obj.getClass()) return false;
BezierProperties other = (BezierProperties) obj;
if (boxColor == null) {
- if (other.boxColor != null)
- return false;
- } else if (!boxColor.equals(other.boxColor))
- return false;
+ if (other.boxColor != null) return false;
+ } else if (!boxColor.equals(other.boxColor)) return false;
if (curveColor == null) {
- if (other.curveColor != null)
- return false;
- } else if (!curveColor.equals(other.curveColor))
- return false;
- if (parts != other.parts)
- return false;
+ if (other.curveColor != null) return false;
+ } else if (!curveColor.equals(other.curveColor)) return false;
+ if (parts != other.parts) return false;
if (pointColor == null) {
- if (other.pointColor != null)
- return false;
- } else if (!pointColor.equals(other.pointColor))
- return false;
- if (Double.doubleToLongBits(scale) != Double.doubleToLongBits(other.scale))
- return false;
+ if (other.pointColor != null) return false;
+ } else if (!pointColor.equals(other.pointColor)) return false;
+ if (Double.doubleToLongBits(scale) != Double.doubleToLongBits(other.scale)) return false;
return true;
}
@Override
public String toString() {
- return "BezierProperties [parts=" + parts + ", scale=" + scale + ", curveColor=" + curveColor + ", pointColor="
- + pointColor + ", boxColor=" + boxColor + "]";
+ return "BezierProperties [parts=" + parts + ", scale=" + scale + ", curveColor=" + curveColor
+ + ", pointColor=" + pointColor + ", boxColor=" + boxColor + "]";
}
}
\ No newline at end of file diff --git a/CSMath/src/bezier/geom/Matrix.java b/CSMath/src/bezier/geom/Matrix.java index a728a02..f9395ea 100644 --- a/CSMath/src/bezier/geom/Matrix.java +++ b/CSMath/src/bezier/geom/Matrix.java @@ -1,44 +1,94 @@ package bezier.geom; +/** + * Matrix class. + * + * @author bjculkin + * + */ public class Matrix { + /** + * Matrix values. + */ public final double[][] mat; + /** + * Create a new matrix, with the specified values. + * + * @param mat + * The matrix to use. + */ public Matrix(double[][] mat) { this.mat = mat; } - + + /** + * Add two matrices together. + * + * @param m + * The matrix to add. + * @return An added matrix. + */ public Matrix add(Matrix m) { return add(m.mat); } - + + /** + * Multiply this matrix by a scalar vector. + * + * @param vec + * The vector to multiply by. + * @return The resulting vector. + */ public double[] scalarMultiply(double[] vec) { double[] ret = new double[vec.length]; - - for(int i = 0; i < mat[0].length; i++) { - for(int j = 0; j < mat.length; j++) { + + for (int i = 0; i < mat[0].length; i++) { + for (int j = 0; j < mat.length; j++) { ret[i] += mat[i][j] * vec[j]; } } - + return ret; } - + + /** + * Add a matrix to this one. + * + * @param matr + * The matrix to add. + * @return The resulting matrix. + */ public Matrix add(double[][] matr) { double[][] ret = new double[mat.length][mat[0].length]; - - for(int i = 0; i < mat.length; i++) { - for(int j = 0; j < mat[0].length; j++) { + + for (int i = 0; i < mat.length; i++) { + for (int j = 0; j < mat[0].length; j++) { ret[i][j] = mat[i][j] + matr[i][j]; } } - + return new Matrix(ret); } - + + /** + * Multiply this matrix by another. + * + * @param m + * The matrix to multiply by + * @return The multiplied matrix. + */ public Matrix multiply(Matrix m) { return multiply(m.mat); } - + + /** + * Multiply this matrix by another. + * + * @param matr + * The matrix to multiply by + * @return The multiplied matrix. + */ public Matrix multiply(double[][] matr) { double[][] ret = new double[mat.length][matr[0].length]; diff --git a/CSMath/src/bezier/geom/transform/TDHCombination.java b/CSMath/src/bezier/geom/transform/TDHCombination.java index 27d71e7..65dec7c 100644 --- a/CSMath/src/bezier/geom/transform/TDHCombination.java +++ b/CSMath/src/bezier/geom/transform/TDHCombination.java @@ -5,7 +5,15 @@ import java.util.List; import bezier.geom.TDHPoint;
+/**
+ * Combination of 2D homogenous transforms.
+ * @author bjculkin
+ *
+ */
public class TDHCombination implements TDHTransform {
+ /**
+ * The transforms that make up this transform.
+ */
public final List<TDHTransform> forms;
@Override
@@ -13,6 +21,10 @@ public class TDHCombination implements TDHTransform { return TDHTransformType.COMBINATION;
}
+ /**
+ * Create a new combined transform.
+ * @param forms The transforms to combine.
+ */
public TDHCombination(TDHTransform... forms) {
this.forms = new ArrayList<>(forms.length);
diff --git a/CSMath/src/bezier/geom/transform/TDHLineReflection.java b/CSMath/src/bezier/geom/transform/TDHLineReflection.java index 0158d60..1ebb76e 100644 --- a/CSMath/src/bezier/geom/transform/TDHLineReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHLineReflection.java @@ -2,11 +2,31 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Transform to reflect across a line.
+ * @author bjculkin
+ *
+ */
public class TDHLineReflection implements TDHTransform {
+ /**
+ * 'a' value for line.
+ */
public final double a;
+ /**
+ * 'b' value for line.
+ */
public final double b;
+ /**
+ * 'c' value for line.
+ */
public final double c;
+ /**
+ * Create a new line-reflect transform.
+ * @param a 'a' value for the line.
+ * @param b 'b' value for the line.
+ * @param c 'c' value for the line.
+ */
public TDHLineReflection(double a, double b, double c) {
this.a = a;
this.b = b;
diff --git a/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java b/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java index 5014d1f..0952703 100644 --- a/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java +++ b/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java @@ -3,13 +3,34 @@ package bezier.geom.transform; import bezier.geom.Matrix;
import bezier.geom.TDHPoint;
+/**
+ * 2D homogenous transform defined by a matrix.
+ *
+ * @author bjculkin
+ *
+ */
public class TDHMatrixTransform implements TDHTransform {
+ /**
+ * The matrix for the transform.
+ */
public final Matrix mat;
+ /**
+ * Create a new matrix-based transform.
+ *
+ * @param mat
+ * The matrix that defines the transform.
+ */
public TDHMatrixTransform(Matrix mat) {
this.mat = mat;
}
+ /**
+ * Create a new matrix-based transform.
+ *
+ * @param mat
+ * The matrix that defines the transform.
+ */
public TDHMatrixTransform(double[][] mat) {
this.mat = new Matrix(mat);
}
@@ -26,6 +47,13 @@ public class TDHMatrixTransform implements TDHTransform { return new TDHPoint(mult[0], mult[1], mult[2]);
}
+ /**
+ * Chain two matrix transforms together.
+ *
+ * @param trans
+ * The next transform to use.
+ * @return A transform that represents the two transforms in serial.
+ */
public TDHTransform then(TDHMatrixTransform trans) {
return new TDHMatrixTransform(mat.multiply(trans.mat));
}
diff --git a/CSMath/src/bezier/geom/transform/TDHPointRotation.java b/CSMath/src/bezier/geom/transform/TDHPointRotation.java index a207612..c92b172 100644 --- a/CSMath/src/bezier/geom/transform/TDHPointRotation.java +++ b/CSMath/src/bezier/geom/transform/TDHPointRotation.java @@ -2,10 +2,27 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Transformation doing rotation about a point.
+ * @author bjculkin
+ *
+ */
public class TDHPointRotation extends TDHRotation {
+ /**
+ * x-coordinate of point.
+ */
public final double x0;
+ /**
+ * y-coordinate of point.
+ */
public final double y0;
+ /**
+ * Create a new point rotation.
+ * @param theta The degrees to rotate about the point.
+ * @param x0 The x-coordinate of the point.
+ * @param y0 The y-coordinate of the point.
+ */
public TDHPointRotation(double theta, double x0, double y0) {
super(theta);
diff --git a/CSMath/src/bezier/geom/transform/TDHRotation.java b/CSMath/src/bezier/geom/transform/TDHRotation.java index a8c4cd6..4cea452 100644 --- a/CSMath/src/bezier/geom/transform/TDHRotation.java +++ b/CSMath/src/bezier/geom/transform/TDHRotation.java @@ -2,9 +2,21 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Rotation transform.
+ * @author bjculkin
+ *
+ */
public class TDHRotation implements TDHTransform {
+ /**
+ * Degrees to rotate.
+ */
public final double theta;
+ /**
+ * Create a new rotation transform.
+ * @param theta The degrees to rotate.
+ */
public TDHRotation(double theta) {
this.theta = theta;
}
@@ -17,11 +29,13 @@ public class TDHRotation implements TDHTransform { return new TDHPoint(x, y, punkt.z);
}
+ @Override
public double[][] matrix() {
return new double[][] { new double[] { Math.cos(theta), Math.sin(theta), 0 },
new double[] { -Math.sin(theta), Math.cos(theta), 0 }, new double[] { 0, 0, 1 } };
}
+ @Override
public TDHTransform invert() {
return new TDHRotation(-theta);
}
diff --git a/CSMath/src/bezier/geom/transform/TDHScale.java b/CSMath/src/bezier/geom/transform/TDHScale.java index 83c7a63..c064f1b 100644 --- a/CSMath/src/bezier/geom/transform/TDHScale.java +++ b/CSMath/src/bezier/geom/transform/TDHScale.java @@ -81,6 +81,7 @@ public class TDHScale implements TDHTransform { return new double[][] { new double[] { sx, 0, 0 }, new double[] { 0, sy, 0 }, new double[] { 0, 0, sz } };
}
+ @Override
public TDHTransform invert() {
return new TDHScale(1 / sx, 1 / sy, 1 / sy);
}
diff --git a/CSMath/src/bezier/geom/transform/TDHShear.java b/CSMath/src/bezier/geom/transform/TDHShear.java index f099e74..7e09b63 100644 --- a/CSMath/src/bezier/geom/transform/TDHShear.java +++ b/CSMath/src/bezier/geom/transform/TDHShear.java @@ -2,8 +2,19 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Shear transform.
+ * @author bjculkin
+ *
+ */
public class TDHShear implements TDHTransform {
+ /**
+ * x-value for shear.
+ */
public final double shx;
+ /**
+ * y-value for shear.
+ */
public final double shy;
@Override
@@ -11,6 +22,11 @@ public class TDHShear implements TDHTransform { return TDHTransformType.SHEAR;
}
+ /**
+ * Create a new shear transform.
+ * @param shx The x-value for shearing.
+ * @param shy The y-value for shearing.
+ */
public TDHShear(double shx, double shy) {
this.shx = shx;
this.shy = shy;
diff --git a/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java b/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java index 21af1a8..0324c88 100644 --- a/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHXAxisReflection.java @@ -2,6 +2,11 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Reflect about x-axis.
+ * @author bjculkin
+ *
+ */
public class TDHXAxisReflection implements TDHTransform {
@Override
public TDHTransformType type() {
diff --git a/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java b/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java index c4ada7f..7e8f6d9 100644 --- a/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java +++ b/CSMath/src/bezier/geom/transform/TDHYAxisReflection.java @@ -2,6 +2,11 @@ package bezier.geom.transform; import bezier.geom.TDHPoint;
+/**
+ * Reflect about y-axis.
+ * @author bjculkin
+ *
+ */
public class TDHYAxisReflection implements TDHTransform {
@Override
public TDHTransformType type() {
diff --git a/CSMath/src/bezier/transforms/geom/TDHCombination.java b/CSMath/src/bezier/transforms/geom/TDHCombination.java deleted file mode 100644 index 22a0b40..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHCombination.java +++ /dev/null @@ -1,64 +0,0 @@ -package bezier.transforms.geom;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import bezier.geom.TDHPoint;
-
-public class TDHCombination implements TDHTransform {
- public final List<TDHTransform> forms;
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.COMBINATION;
- }
-
- public TDHCombination(TDHTransform... forms) {
- this.forms = new ArrayList<>(forms.length);
-
- for (TDHTransform form : forms) {
- this.forms.add(form);
- }
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- TDHPoint ret = punkt;
-
- for (TDHTransform form : forms) {
- ret = form.transform(ret);
- }
-
- return ret;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((forms == null) ? 0 : forms.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHCombination other = (TDHCombination) obj;
- if (forms == null) {
- if (other.forms != null)
- return false;
- } else if (!forms.equals(other.forms))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHCombination [forms=" + forms + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHIdentity.java b/CSMath/src/bezier/transforms/geom/TDHIdentity.java deleted file mode 100644 index f24d1c9..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHIdentity.java +++ /dev/null @@ -1,21 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-/**
- * A transform that does nothing.
- *
- * @author bjculkin
- *
- */
-public class TDHIdentity implements TDHTransform {
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- return punkt;
- }
-
- @Override
- public String toString() {
- return "TDHIdentity []";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHLineReflection.java b/CSMath/src/bezier/transforms/geom/TDHLineReflection.java deleted file mode 100644 index cf1e8c2..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHLineReflection.java +++ /dev/null @@ -1,68 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHLineReflection implements TDHTransform {
- public final double a;
- public final double b;
- public final double c;
-
- public TDHLineReflection(double a, double b, double c) {
- this.a = a;
- this.b = b;
- this.c = c;
- }
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.REFLECTION;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double com = (a * a - b * b);
-
- double x = (punkt.x * com) - (2 * a * b * punkt.y) - (2 * a * c * punkt.z);
- double y = (-2 * a * b * punkt.x) + (punkt.y * com) - (2 * b * c * punkt.z);
- double z = (punkt.z * com);
-
- return new TDHPoint(x, y, z);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits(a);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(b);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(c);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHLineReflection other = (TDHLineReflection) obj;
- if (Double.doubleToLongBits(a) != Double.doubleToLongBits(other.a))
- return false;
- if (Double.doubleToLongBits(b) != Double.doubleToLongBits(other.b))
- return false;
- if (Double.doubleToLongBits(c) != Double.doubleToLongBits(other.c))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHLineReflection [a=" + a + ", b=" + b + ", c=" + c + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java b/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java deleted file mode 100644 index ace590d..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHMatrixTransform.java +++ /dev/null @@ -1,32 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.Matrix;
-import bezier.geom.TDHPoint;
-
-public class TDHMatrixTransform implements TDHTransform {
- public final Matrix mat;
-
- public TDHMatrixTransform(Matrix mat) {
- this.mat = mat;
- }
-
- public TDHMatrixTransform(double[][] mat) {
- this.mat = new Matrix(mat);
- }
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.MATRIX;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double[] mult = mat.scalarMultiply(new double[] { punkt.x, punkt.y, punkt.z });
-
- return new TDHPoint(mult[0], mult[1], mult[2]);
- }
-
- public TDHTransform then(TDHMatrixTransform trans) {
- return new TDHMatrixTransform(mat.multiply(trans.mat));
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHPointRotation.java b/CSMath/src/bezier/transforms/geom/TDHPointRotation.java deleted file mode 100644 index bc3c716..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHPointRotation.java +++ /dev/null @@ -1,67 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHPointRotation extends TDHRotation {
- public final double x0;
- public final double y0;
-
- public TDHPointRotation(double theta, double x0, double y0) {
- super(theta);
-
- this.x0 = x0;
- this.y0 = y0;
- }
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.ROTATION;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double x1 = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta));
- double y1 = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta));
-
- double x2 = (-x0 * Math.cos(theta)) + (y0 * Math.sin(theta)) + x0;
- double y2 = (-x0 * Math.sin(theta)) - (y0 * Math.cos(theta)) + y0;
-
- double x = x1 + (punkt.z * x2);
- double y = y1 + (punkt.z * y2);
-
- return new TDHPoint(x, y, punkt.z);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- long temp;
- temp = Double.doubleToLongBits(x0);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(y0);
- 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;
- TDHPointRotation other = (TDHPointRotation) obj;
- if (Double.doubleToLongBits(x0) != Double.doubleToLongBits(other.x0))
- return false;
- if (Double.doubleToLongBits(y0) != Double.doubleToLongBits(other.y0))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHPointRotation [x0=" + x0 + ", y0=" + y0 + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHRotation.java b/CSMath/src/bezier/transforms/geom/TDHRotation.java deleted file mode 100644 index 8870b53..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHRotation.java +++ /dev/null @@ -1,57 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHRotation implements TDHTransform {
- public final double theta;
-
- public TDHRotation(double theta) {
- this.theta = theta;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double x = (punkt.x * Math.cos(theta)) - (punkt.y * Math.sin(theta));
- double y = (punkt.x * Math.sin(theta)) - (punkt.y * Math.cos(theta));
-
- return new TDHPoint(x, y, punkt.z);
- }
-
- public double[][] matrix() {
- return new double[][] { new double[] { Math.cos(theta), Math.sin(theta), 0 },
- new double[] { -Math.sin(theta), Math.cos(theta), 0 }, new double[] { 0, 0, 1 } };
- }
-
- public TDHTransform invert() {
- return new TDHRotation(-theta);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits(theta);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHRotation other = (TDHRotation) obj;
- if (Double.doubleToLongBits(theta) != Double.doubleToLongBits(other.theta))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHRotation [theta=" + theta + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHScale.java b/CSMath/src/bezier/transforms/geom/TDHScale.java deleted file mode 100644 index a6db9a9..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHScale.java +++ /dev/null @@ -1,124 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-/**
- * Transform that does coordinate scaling.
- *
- * @author bjculkin
- *
- */
-public class TDHScale implements TDHTransform {
- /**
- * Amount to scale x by.
- */
- public final double sx;
- /**
- * Amount to scale y by.
- */
- public final double sy;
- /**
- * Amount to scale the homogeneous coordinate by.
- */
- public final double sz;
-
- /**
- * Create a new scaling that scales each coordinate by an equal amount
- *
- * @param factor
- * The amount to scale the coordinates by.
- */
- public TDHScale(double factor) {
- this(factor, factor);
- }
-
- /**
- * Create a new scaling that scales each coordinate separately.
- *
- * @param sx
- * The amount to scale x by.
- * @param sy
- * The amount to scale y by.
- */
- public TDHScale(double sx, double sy) {
- this(sx, sy, 1);
- }
-
- /**
- * Create a new scaling that scales each coordinate separately.
- *
- * Includes the homogeneous coordinate.
- *
- * @param sx
- * The amount to scale x by.
- * @param sy
- * The amount to scale y by.
- * @param sz
- * The amount to scale the homogeneous coordinate by.
- */
- public TDHScale(double sx, double sy, double sz) {
- this.sx = sx;
- this.sy = sy;
- this.sz = sz;
- }
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.SCALE;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double x = punkt.x * sx;
- double y = punkt.y * sy;
- double z = punkt.z * sz;
-
- return new TDHPoint(x, y, z);
- }
-
- @Override
- public double[][] matrix() {
- return new double[][] { new double[] { sx, 0, 0 }, new double[] { 0, sy, 0 }, new double[] { 0, 0, sz } };
- }
-
- public TDHTransform invert() {
- return new TDHScale(1 / sx, 1 / sy, 1 / sy);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits(sx);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(sy);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(sz);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHScale other = (TDHScale) obj;
- if (Double.doubleToLongBits(sx) != Double.doubleToLongBits(other.sx))
- return false;
- if (Double.doubleToLongBits(sy) != Double.doubleToLongBits(other.sy))
- return false;
- if (Double.doubleToLongBits(sz) != Double.doubleToLongBits(other.sz))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHScale [sx=" + sx + ", sy=" + sy + ", sz=" + sz + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHShear.java b/CSMath/src/bezier/transforms/geom/TDHShear.java deleted file mode 100644 index c0c72ca..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHShear.java +++ /dev/null @@ -1,59 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHShear implements TDHTransform {
- public final double shx;
- public final double shy;
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.SHEAR;
- }
-
- public TDHShear(double shx, double shy) {
- this.shx = shx;
- this.shy = shy;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double x = punkt.x + (punkt.y * shx);
- double y = punkt.y + (punkt.x * shy);
-
- return new TDHPoint(x, y, punkt.z);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits(shx);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(shy);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHShear other = (TDHShear) obj;
- if (Double.doubleToLongBits(shx) != Double.doubleToLongBits(other.shx))
- return false;
- if (Double.doubleToLongBits(shy) != Double.doubleToLongBits(other.shy))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHShear [shx=" + shx + ", shy=" + shy + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTransform.java b/CSMath/src/bezier/transforms/geom/TDHTransform.java deleted file mode 100644 index 20afc53..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHTransform.java +++ /dev/null @@ -1,54 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-/**
- * Transformation applicable to TDHPoints.
- *
- * @author bjculkin
- *
- */
-@FunctionalInterface
-public interface TDHTransform {
- /**
- * Get the type of this transform.
- *
- * Unknown transformations are assumed to be identity transforms.
- *
- * @return The type of this transform.
- */
- default TDHTransformType type() {
- return TDHTransformType.IDENTITY;
- }
-
- /**
- * Get the matrix representation of the transform.
- *
- * Unknown transformations are assumed to be identity transforms.
- *
- * @return The matrix representation of the transform.
- */
- default double[][] matrix() {
- return new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { 0, 0, 1 } };
- }
-
- /**
- * Get the inverse of the transform.
- *
- * Unknown transformations are assumed to be identity transforms.
- *
- * @return The inverse the transform.
- */
- default TDHTransform invert() {
- return new TDHIdentity();
- }
-
- /**
- * Apply the transform to a point.
- *
- * @param punkt
- * The point to transform.
- * @return A transformed version of the point.
- */
- TDHPoint transform(TDHPoint punkt);
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTransformType.java b/CSMath/src/bezier/transforms/geom/TDHTransformType.java deleted file mode 100644 index 909afdc..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHTransformType.java +++ /dev/null @@ -1,42 +0,0 @@ -package bezier.transforms.geom;
-
-/**
- * Types of transform to apply to TDHPoints.
- *
- * @author bjculkin
- *
- */
-public enum TDHTransformType {
- /**
- * Coordinate translation.
- */
- TRANSLATE,
- /**
- * Do nothing transform.
- */
- IDENTITY,
- /**
- * Coordinate scaling.
- */
- SCALE,
- /**
- * Coordinate rotation.
- */
- ROTATION,
- /**
- * Coordinate reflection.
- */
- REFLECTION,
- /**
- * Coordinate shearing.
- */
- SHEAR,
- /**
- * Multiple transformations.
- */
- COMBINATION,
- /**
- * Arbitrary matrix transformation.
- */
- MATRIX
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHTranslate.java b/CSMath/src/bezier/transforms/geom/TDHTranslate.java deleted file mode 100644 index 905711f..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHTranslate.java +++ /dev/null @@ -1,89 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-/**
- * A transform that does coordinate translation.
- *
- * @author bjculkin
- *
- */
-public class TDHTranslate implements TDHTransform {
- /**
- * The amount to translate the x-coordinate by.
- */
- public final double h;
- /**
- * The amount to translate the y-coordinate by.
- */
- public final double k;
-
- /**
- * Create a new translation transform.
- *
- * @param h
- * The amount to translate x by.
- * @param k
- * The amount to translate y by.
- */
- public TDHTranslate(double h, double k) {
- this.h = h;
- this.k = k;
- }
-
- @Override
- public TDHTransformType type() {
- return TDHTransformType.TRANSLATE;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- double x = punkt.x + (punkt.z * h);
- double y = punkt.y + (punkt.z * k);
-
- return new TDHPoint(x, y, punkt.z);
- }
-
- @Override
- public double[][] matrix() {
- return new double[][] { new double[] { 1, 0, 0 }, new double[] { 0, 1, 0 }, new double[] { h, k, 1 } };
- }
-
- @Override
- public TDHTransform invert() {
- return new TDHTranslate(-h, -k);
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- long temp;
- temp = Double.doubleToLongBits(h);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- temp = Double.doubleToLongBits(k);
- result = prime * result + (int) (temp ^ (temp >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- TDHTranslate other = (TDHTranslate) obj;
- if (Double.doubleToLongBits(h) != Double.doubleToLongBits(other.h))
- return false;
- if (Double.doubleToLongBits(k) != Double.doubleToLongBits(other.k))
- return false;
- return true;
- }
-
- @Override
- public String toString() {
- return "TDHTranslate [h=" + h + ", k=" + k + "]";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java b/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java deleted file mode 100644 index 4b4bffe..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHXAxisReflection.java +++ /dev/null @@ -1,20 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHXAxisReflection implements TDHTransform {
- @Override
- public TDHTransformType type() {
- return TDHTransformType.REFLECTION;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- return new TDHPoint(punkt.x, -punkt.y, punkt.z);
- }
-
- @Override
- public String toString() {
- return "TDHXAxisReflection []";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java b/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java deleted file mode 100644 index 39e9f18..0000000 --- a/CSMath/src/bezier/transforms/geom/TDHYAxisReflection.java +++ /dev/null @@ -1,20 +0,0 @@ -package bezier.transforms.geom;
-
-import bezier.geom.TDHPoint;
-
-public class TDHYAxisReflection implements TDHTransform {
- @Override
- public TDHTransformType type() {
- return TDHTransformType.REFLECTION;
- }
-
- @Override
- public TDHPoint transform(TDHPoint punkt) {
- return new TDHPoint(-punkt.x, punkt.y, punkt.z);
- }
-
- @Override
- public String toString() {
- return "TDHYAxisReflection []";
- }
-}
\ No newline at end of file diff --git a/CSMath/src/bisection/Bisection.java b/CSMath/src/bisection/Bisection.java index edca743..324d127 100644 --- a/CSMath/src/bisection/Bisection.java +++ b/CSMath/src/bisection/Bisection.java @@ -8,12 +8,21 @@ package bisection; * Use the bisection method to find bracketed roots of arbitrary real-valued functions.
*/
+/**
+ * Bisect a curve to find bracketed roots of arbitrary real-valued functions.
+ * @author bjculkin
+ *
+ */
public class Bisection {
/**
* Maximum number of iterations to attempt.
*/
public static final int MAXITR = 500;
+ /**
+ * Main method.
+ * @param args Unused CLI args.
+ */
public static void main(String[] args) {
/* The variable to manipulate in the expressions. */
Dual varX = new Dual();
@@ -115,6 +124,15 @@ public class Bisection { return newmid;
}
+ /**
+ * Bisect an arbitrary expression using the secant method.
+ * @param func The expression to bisect.
+ * @param var The variable to manipulate.
+ * @param lo The lower bounding value.
+ * @param hi The higher bounding value.
+ * @param tol The tolerance to find the answer to.
+ * @return The bisected root for the expression, within the specified tolerance.
+ */
public static double secant(DualExpr func, Dual var, double lo, double hi, double tol) {
/* Initial guesses for root. */
double guess1 = (lo + hi) / 3; // 1/3 into the range
diff --git a/CSMath/src/bisection/PreBisection.java b/CSMath/src/bisection/PreBisection.java index 39bbd60..ef56610 100644 --- a/CSMath/src/bisection/PreBisection.java +++ b/CSMath/src/bisection/PreBisection.java @@ -9,7 +9,16 @@ package bisection; */
import java.util.function.DoubleUnaryOperator;
+/**
+ * Previous attempt at bisection.
+ * @author bjculkin
+ *
+ */
public class PreBisection {
+ /**
+ * Main method.
+ * @param args Unused CLI args.
+ */
public static void main(String[] args) {
// The functions we're approximating a root for
DoubleUnaryOperator functionA = x -> Math.cos(x) - x;
|
