org.jcurl.math
Class ShaperUtils

Package class diagram package ShaperUtils
java.lang.Object
  extended by org.jcurl.math.ShaperUtils

public abstract class ShaperUtils
extends Object

Helper for convenient approximated Java2D drawing of arbitratry R1RNFunctions with at least 2 dimensions.

Version:
$Id: ShaperUtils.java 1031 2009-07-23 15:06:05Z mro $
Author:
M. Rohrmoser
See Also:
Shaper, Shapeable

Constructor Summary
ShaperUtils()
           
 
Method Summary
(package private) static void curveTo(R1RNFunction f, double tmin, double tmax, GeneralPath gp, float zoom)
          Compute the control points and add one Cubic Bezier Curve to a GeneralPath.
static Shape interpolateCubic(R1RNFunction src, double min, double max, int curves, float zoom, Interpolator ip)
          Interpolate using Cubic Bezier Curves.
static Shape interpolateLinear(R1RNFunction src, double min, double max, int curves, float zoom, Interpolator ip)
          Interpolate using Linear Bezier Curves.
static Shape interpolateQuadratic(R1RNFunction src, double min, double max, int curves, float zoom, Interpolator ip)
          Interpolate using Quadratic Bezier Curves.
(package private) static void lineTo(R1RNFunction f, double tmax, GeneralPath gp, float zoom)
          Add one Linear Bezier Curve to a GeneralPath.
(package private) static void quadTo(R1RNFunction f, double tmin, double tmax, GeneralPath gp, float zoom)
          Compute the control point and add one Quadratic Bezier Curve to a GeneralPath.
(package private) static String toString(double[] arr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShaperUtils

public ShaperUtils()
Method Detail

curveTo

static void curveTo(R1RNFunction f,
                    double tmin,
                    double tmax,
                    GeneralPath gp,
                    float zoom)
Compute the control points and add one Cubic Bezier Curve to a GeneralPath. Does no initial GeneralPath.moveTo(float, float).

Approximation algorithm

This ansatz uses no adaptive optimisation but the nature of curves as they're typical to curling:

So we use

This causes quite a computation - without iteration/recursion though, but 1 square root and many double multiplications - but this is well worth while as we can reduce the curve segments to draw significantly. One cubic bezier curve per seven meters curve length gives an error < 2 mm (using CurlerDenny with 24s draw-to-tee and 1m curl)!

TODO maybe re-use endpoint location and velocity. This can cause pain at C1 discontinuous t's (collissions).

Maxima Solution

        radsubstflag: true$
        k1_0 = k0_0 + l * v0_0;
        k1_1 = k0_1 + l * v0_1;
        k2_0 = k3_0 - n * v3_0;
        k2_1 = k3_1 - n * v3_1;
        l/n=a/c;
        ((k2_0 - k1_0)*(k2_0 - k1_0) + (k2_1 - k1_1)*(k2_1 - k1_1)) / (n*n) = b*b / (c*c);
        solve([%th(6), %th(5), %th(4), %th(3), %th(2), %th(1)],[k1_0, k1_1, k2_0, k2_1, l, n]);
        factor(%);
        ratsimp(%);
        ratsubst(V0, v0_1ˆ2+v0_0ˆ2, %);
        ratsubst(V3, v3_1ˆ2+v3_0ˆ2, %);
        ratsubst(A, k0_1-k3_1, %);
        ratsubst(B, k0_0-k3_0, %);
        ratsubst(T, 2*a*c*v0_0*v3_0+aˆ2*v0_1ˆ2+aˆ2*v0_0ˆ2-bˆ2, %);
        ratsubst(Q, cˆ2*V3+aˆ2*V0+T+2*a*c*v0_1*v3_1-aˆ2*v0_1ˆ2-aˆ2*v0_0ˆ2, %);
        ratsubst(W, Bˆ2*T+Bˆ2*(bˆ2-Q)+cˆ2*(v3_0ˆ2*Bˆ2-v3_0ˆ2*Aˆ2)-aˆ2*v0_1ˆ2*Bˆ2+v3_1*(2*cˆ2*v3_0*A*B
        +2*a*c*v0_0*A*B)+v0_1*(2*a*c*v3_0*A*B+2*aˆ2*v0_0*A*B)-2*a*c*v0_0*v3_0*Aˆ2-aˆ2*v0_0ˆ2*Aˆ2
        +bˆ2*Aˆ2, %);
        expand(%);
        factor(%);
        ratsubst(R, c*v3_0*B+a*v0_0*B+c*v3_1*A+a*v0_1*A, %);
 


interpolateCubic

public static Shape interpolateCubic(R1RNFunction src,
                                     double min,
                                     double max,
                                     int curves,
                                     float zoom,
                                     Interpolator ip)
Interpolate using Cubic Bezier Curves.

Computes the required intermediate t samples and delegates to curveTo(R1RNFunction, double, double, GeneralPath, float) to compute the interpolating curve segments.

Parameters:
src - the (at least 2-dimensional) curve. Higher dimensions are ignored.
min - the min input t to R1RNFunction.at(double, int, int)
max - the max input t to R1RNFunction.at(double, int, int)
curves - the number of interpolating cubic bezier curves - must be >= 1.
zoom - graphics zoom factor (typically 1)
ip - the Interpolator to get the intermediate t sample values.
See Also:
curveTo(R1RNFunction, double, double, GeneralPath, float)

interpolateLinear

public static Shape interpolateLinear(R1RNFunction src,
                                      double min,
                                      double max,
                                      int curves,
                                      float zoom,
                                      Interpolator ip)
Interpolate using Linear Bezier Curves.

Computes the required intermediate t samples and delegates to lineTo(R1RNFunction, double, GeneralPath, float) to compute the interpolating curve segments.

Parameters:
src - the (at least 2-dimensional) curve. Higher dimensions are ignored.
min - the min input t to R1RNFunction.at(double, int, int)
max - the max input t to R1RNFunction.at(double, int, int)
curves - the number of line segments - must be >= 1.
zoom - graphics zoom factor (typically 1)
ip - the Interpolator to get the intermediate sample t values.
See Also:
lineTo(R1RNFunction, double, GeneralPath, float)

interpolateQuadratic

public static Shape interpolateQuadratic(R1RNFunction src,
                                         double min,
                                         double max,
                                         int curves,
                                         float zoom,
                                         Interpolator ip)
Interpolate using Quadratic Bezier Curves.

Computes the required intermediate t samples and delegates to quadTo(R1RNFunction, double, double, GeneralPath, float) to compute the interpolating curve segments.

Parameters:
src - the (2-dimensional) curve. Higher dimensions are ignored.
min - the min input t to R1RNFunction.at(double, int, int)
max - the max input t to R1RNFunction.at(double, int, int)
curves - the number of line segments - must be >= 1.
zoom - graphics zoom factor (typically 1)
ip - the Interpolator to get the intermediate sample t values.
See Also:
quadTo(R1RNFunction, double, double, GeneralPath, float)

lineTo

static final void lineTo(R1RNFunction f,
                         double tmax,
                         GeneralPath gp,
                         float zoom)
Add one Linear Bezier Curve to a GeneralPath. Does no initial GeneralPath.moveTo(float, float).

Approximation algorithm

Just connect start- and endpoint.

TODO maybe re-use endpoint location and velocity. This can cause pain at C1 discontinuous t's (collissions).


quadTo

static final void quadTo(R1RNFunction f,
                         double tmin,
                         double tmax,
                         GeneralPath gp,
                         float zoom)
Compute the control point and add one Quadratic Bezier Curve to a GeneralPath. Does no initial GeneralPath.moveTo(float, float).

Approximation algorithm

This ansatz uses no adaptive optimisation but only

TODO maybe re-use endpoint location and velocity. This can cause pain at C1 discontinuous t's (collissions).

Maxima Solution

 radsubstflag: true$
 k0_0 + l * v0_0 = k2_0 + m * v2_0;
 k0_1 + l * v0_1 = k2_1 + m * v2_1;
 solve([%th(2),%th(1)],[l,m]);
 subst(q, v0_1 * v2_0 - v0_0 * v2_1, %);
 subst(dx_0 + k0_0, k2_0, %);
 subst(dx_1 + k0_1, k2_1, %);
 ratsimp(%);
 


toString

static String toString(double[] arr)


Copyright © 2005-2009 jcurl.org. All Rights Reserved.