2
votes

I have multiple cubic curve that form shape I want to convert this shape to a polygon without loosing the curvatures of the curves they. I have a start point ,end point and two controls for each curve. Is there any algorithm or a way to convert this set of curves into polygon of multiple points? Thanks in advance

private List<CubicCurve> curves = new ArrayList<>();

each red point represent the end of one curve and the start of the next the two green dots between two red dots represent the the control points of the curve

enter image description here

2
Needs code. I don't see how we give an answer that isn't a guess about what you are actually trying to do.markspace
Are you just asking for the equation of a cubic Bezier curve?James_D
if i understood the equation correctly then i think that what i want. i just want to get corordinates of points along the curve from start to that end if i just have the four pointsAhmed Elshorbagy
how to convert points to (X,Y) cordinates @James_DAhmed Elshorbagy
I'm confused. You must know those points to draw the cubic curves. So just plug their values into the equation, use varying values of t from 0 to 1, and for each value of t the equation gives you a point on the curve.James_D

2 Answers

2
votes

I have a much simpler and probably also more efficient solution to the above problem of finding the intermediate points of a Shape contour. It also uses the PathTransition but in a more straight forward way. I have only tested it with a Circle but I think this works with any Shape.

public static void main(String[] args) {
    Shape shape = new Circle(100);
    PathTransition pt = new PathTransition(Duration.ONE, shape, new Circle());
    long t0 = System.currentTimeMillis();
    pt.playFromStart(); // force initialization
    pt.stop();
    for (double frac = 0.0; frac <= 1.0; frac += 0.05) {
        pt.interpolate(frac);
        System.out.println(pt.getNode().getTranslateX() + " " + pt.getNode().getTranslateY());
    }
    long t1 = System.currentTimeMillis();
    System.out.println("Evaluation took: " + (t1 - t0) + "ms");
}
1
votes

This process is called "curve flattening".

It suffices to compute intermediate points on the curve using the parametric equations, and recursively subdivide until the height of the triangle they form becomes neglectible.

enter image description here