diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-08-22 20:01:40 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2019-08-22 20:01:40 -0400 |
| commit | 20bef6e26d948698398bd16aeab8c9e6b89110e4 (patch) | |
| tree | 8a21e17f78b330435f4ce2d4355d72b773230aa7 /src/main/java/com | |
| parent | 26fb28edd1ebb6390f8803fed3876d222cb8fdba (diff) | |
Format/import cleanup
Diffstat (limited to 'src/main/java/com')
| -rwxr-xr-x | src/main/java/com/pau101/util/BezierUtils.java | 53 | ||||
| -rwxr-xr-x | src/main/java/com/pau101/util/CubicBezier.java | 16 |
2 files changed, 24 insertions, 45 deletions
diff --git a/src/main/java/com/pau101/util/BezierUtils.java b/src/main/java/com/pau101/util/BezierUtils.java index 27b82d5..cc57252 100755 --- a/src/main/java/com/pau101/util/BezierUtils.java +++ b/src/main/java/com/pau101/util/BezierUtils.java @@ -11,14 +11,13 @@ public final class BezierUtils { * Compute the value of all nth degree Bernstein polynomials. * * @param curveDegree - * : degree of curve + * : degree of curve * @param t - * : curve parameter on interval [0,1] + * : curve parameter on interval [0,1] * @param scalars - * : curveDegree + 1 Bernstein values. + * : curveDegree + 1 Bernstein values. */ - public static void allBernstein(int curveDegree, float t, - float scalars[]) { + public static void allBernstein(int curveDegree, float t, float scalars[]) { int j, k; float nt = 1 - t; float saved; @@ -38,16 +37,15 @@ public final class BezierUtils { * Compute point of nth degree Bezier curve. * * @param controlPoints - * : curveDegree + 1 control points + * : curveDegree + 1 control points * @param curveDegree - * : degree of curve + * : degree of curve * @param t - * : curve parameter on interval [0,1] + * : curve parameter on interval [0,1] * @param point - * : resulting point + * : resulting point */ - public static void pointOnBezierCurve(float controlPoints[][], - int curveDegree, float t, float point[]) { + public static void pointOnBezierCurve(float controlPoints[][], int curveDegree, float t, float point[]) { float scalars[] = new float[curveDegree + 1]; int k; allBernstein(curveDegree, t, scalars); @@ -60,51 +58,40 @@ public final class BezierUtils { } /** - * Compute an approximate length of a Bezier curve given the - * control points. + * Compute an approximate length of a Bezier curve given the control points. * * @param controlPoints - * : control points of a Bezier curve + * : control points of a Bezier curve * @return the approximate length */ public static float approximateLength(float controlPoints[][]) { float length = 0; for (int i = 0; i < controlPoints.length - 1; i++) { - float xDif = controlPoints[i + 1][0] - - controlPoints[i][0]; - float yDif = controlPoints[i + 1][1] - - controlPoints[i][1]; - float zDif = controlPoints[i + 1][2] - - controlPoints[i][2]; - length += Math.sqrt(xDif * xDif + yDif * yDif - + zDif * zDif); + float xDif = controlPoints[i + 1][0] - controlPoints[i][0]; + float yDif = controlPoints[i + 1][1] - controlPoints[i][1]; + float zDif = controlPoints[i + 1][2] - controlPoints[i][2]; + length += Math.sqrt(xDif * xDif + yDif * yDif + zDif * zDif); } return length; } - public static int tesselationSegementsForLength(float length, - float scale) { + public static int tesselationSegementsForLength(float length, float scale) { float noLessThan = 10 * scale; float segs = length * scale / 30F; - return (int) Math.ceil(Math.sqrt(segs * segs * 0.6 - + noLessThan * noLessThan)); + return (int) Math.ceil(Math.sqrt(segs * segs * 0.6 + noLessThan * noLessThan)); } public static float[][] curve(float controlPoints[][]) { return curve(controlPoints, 1); } - public static float[][] curve(float controlPoints[][], - float scale) { - int count = tesselationSegementsForLength( - approximateLength(controlPoints), scale); + public static float[][] curve(float controlPoints[][], float scale) { + int count = tesselationSegementsForLength(approximateLength(controlPoints), scale); float[][] points = new float[count][3]; for (int i = 0; i < count; i++) { float t = i / (float) (count - 1); float[] point = new float[3]; - pointOnBezierCurve(controlPoints, - controlPoints.length - 1, t, - point); + pointOnBezierCurve(controlPoints, controlPoints.length - 1, t, point); points[i] = point; } return points; diff --git a/src/main/java/com/pau101/util/CubicBezier.java b/src/main/java/com/pau101/util/CubicBezier.java index b681517..7071994 100755 --- a/src/main/java/com/pau101/util/CubicBezier.java +++ b/src/main/java/com/pau101/util/CubicBezier.java @@ -8,18 +8,10 @@ public class CubicBezier { public CubicBezier(float a1, float b1, float a2, float b2) { controlPoints = new float[4][]; - controlPoints[0] = new float[] { - 0, 0 - }; - controlPoints[1] = new float[] { - a1, b1 - }; - controlPoints[2] = new float[] { - a2, b2 - }; - controlPoints[3] = new float[] { - 1, 1 - }; + controlPoints[0] = new float[] { 0, 0 }; + controlPoints[1] = new float[] { a1, b1 }; + controlPoints[2] = new float[] { a2, b2 }; + controlPoints[3] = new float[] { 1, 1 }; } public float eval(float t) { |
