Results 1 to 2 of 2
  1. #1
    Paul Richards is offline Member
    Join Date
    Oct 2008
    Location
    UK
    Posts
    65
    Rep Power
    0

    Default 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:
    1. Write a function bezierDiff(t), which differentiates the Bezier curve.
    2. For each point, t, calculate the perpendicular = -1/bezierDiff(t).
    3. Use Pythagras's theorem to find the location of the two points on the perpendicular, which are d units away.
    4. 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.
    5. 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.
    6. 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
    Attached Thumbnails Attached Thumbnails Linked Bezier Curves-neckband.jpg  

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Arrow 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"}
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Similar Threads

  1. Replies: 1
    Last Post: 06-30-2010, 07:12 PM
  2. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 03:15 AM
  3. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 03:42 AM
  4. question about linked lists
    By jkurth in forum Advanced Java
    Replies: 1
    Last Post: 11-11-2007, 08:33 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •