-
1 Attachment(s)
Linked Bezier Curves
I have a question that isn't specifically Java, but am not sure where to ask. My task is to draw a neck band on a cardigan. I have a cubic Bezier curve, drawn with Path2D.Double and curveTo, but thats maybe not that relevant. The user can manipulate this curve in my program.
The problem is: I want to draw another curve which starts and ends at specific places, which are the same distance (call this d) from the start and end points of the other curve. The points on my new curve are always distance d from one point on my original curve. See the attachment for an illustration (although this is not a cubic curve, its just knocked up in MS Paint :)).
I have started to implement this by the following algorithm:
- Write a function bezierDiff(t), which differentiates the Bezier curve.
- For each point, t, calculate the perpendicular = -1/bezierDiff(t).
- Use Pythagras's theorem to find the location of the two points on the perpendicular, which are d units away.
- Write a function newCurvePoint(t), which returns a Point2D.Double object. It uses the previous calculations to get the two points then chooses the correct one.
- You have to find out the starting and ending values of t, to plug into newCurvePoint. Note that these will not necessarily be 0 and 1 since I want one start point to be directly below the Bezier start, and the other to be directly to the left of it. You have to solve cubic equations to do this.
- Use a simple for loop to construct a series of line segments from the start to the end, this approximates the required curve.
The algebra behind this is really messy and its a complicated approach. Is there an easier way to solve the problem? In particular, can the new curve be constructed as a Bezier curve, and if so, is there any easy way of finding the control points? I have tried various heuristics but none give a consistent distance between the two curves.
Thanks (in anticipation)
Paul
-
Sergei Bernstein
Okay, it's messy. I have found that it is in general simpler to write someting that is not otherwise available in Java, your posts seem to demonstrate the needed skill level. Try this:
Bezier Demo
and
Bill Casselman
In general, it will be dy/dx at some point and doing some simple trig to get the normal, or more correctly as you posted. I have been working on some deep problems in ai and this sort of advanced problem but ready-made and handy-dandy solutions used in an OO manner tend to not have sophisticated and advanced work acutally done.
I had a friend who was a tanker for the Army, who had a contact in advanced programming. This was that person's advice also. I suggest diggin in, if a mathemetician can provide the correct formulae, coding devolves easily.
{ should be moved to "Programming in General"}