CubicCurve2D Tracing  
Author Message
mearvk





PostPosted: 2008-3-7 20:54:00 Top

java-programmer, CubicCurve2D Tracing Given an arbitrary CubicCurve2D how can I iterate along it getting
both the x and y coordinates of the current point as I go?

Thanks.
 
Daniel Pitts





PostPosted: 2008-3-9 1:30:00 Top

java-programmer >> CubicCurve2D Tracing mearvk wrote:
> Given an arbitrary CubicCurve2D how can I iterate along it getting
> both the x and y coordinates of the current point as I go?
>
> Thanks.
Try: calling getPathIterator on it.
<http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Shape.html#getPathIterator(java.awt.geom.AffineTransform)>


--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
mearvk





PostPosted: 2008-3-9 11:21:00 Top

java-programmer >> CubicCurve2D Tracing On Mar 8, 12:29爌m, Daniel Pitts
<email***@***.com> wrote:
> mearvk wrote:
> > Given an arbitrary CubicCurve2D how can I iterate along it getting
> > both the x and y coordinates of the current point as I go?
>
> > Thanks.
>
> Try: calling getPathIterator on it.
> <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Shape.html#getPathIt...)>
>
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Looking at the API I think PathIterator's currentSegment() will just
get me the beginning, end and both control points. What I need is a
way to, for instance, find the length of or iterate over, pixel by
pixel, an arbitrary bezier curve. What I am actually doing is trying
to find the shortest path along a pair of bezier curves (think race
track) using a third bezier curve (think finding the apex). But how to
grade the quality of the current best path? Surely the simplest thing
to do would be to ask how long is the line? I was thinking if there
were a way to map the start, end, and both control points onto a
mathematical function, then I could just scale it appropriately and
iterate pixel by pixel, summing as I go, but I'm not sure if this can
be done.
 
 
Daniel Pitts





PostPosted: 2008-3-10 23:01:00 Top

java-programmer >> CubicCurve2D Tracing mearvk wrote:
> On Mar 8, 12:29 pm, Daniel Pitts
> <email***@***.com> wrote:
>> mearvk wrote:
>>> Given an arbitrary CubicCurve2D how can I iterate along it getting
>>> both the x and y coordinates of the current point as I go?
>>> Thanks.
>> Try: calling getPathIterator on it.
>> <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Shape.html#getPathIt...)>
>>
>> --
>> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
>
> Looking at the API I think PathIterator's currentSegment() will just
> get me the beginning, end and both control points. What I need is a
> way to, for instance, find the length of or iterate over, pixel by
> pixel, an arbitrary bezier curve. What I am actually doing is trying
> to find the shortest path along a pair of bezier curves (think race
> track) using a third bezier curve (think finding the apex). But how to
> grade the quality of the current best path? Surely the simplest thing
> to do would be to ask how long is the line? I was thinking if there
> were a way to map the start, end, and both control points onto a
> mathematical function, then I could just scale it appropriately and
> iterate pixel by pixel, summing as I go, but I'm not sure if this can
> be done.
This might help:
<http://java.sun.com/j2se/1.4.2/docs/api/java/awt/geom/FlatteningPathIterator.html>

Also, Bezier curves are well defined mathematically, there is quite
likely a formula to find the length given the endpoints and control points.

A quick google turned up:
<http://www.cit.gu.edu.au/~anthony/info/graphics/bezier.curves>

Its actually an integral, so you are going about it in a reasonable way.
FlatteningPathIterator is what you want. Just sum the distance between
any two endpoints it gives you.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
 
 
tar





PostPosted: 2008-3-11 1:56:00 Top

java-programmer >> CubicCurve2D Tracing
Well, you can get some results by Googling "bezier curve length"

One promising approach, with C code, is:

<http://steve.hollasch.net/cgindex/curves/cbezarclen.html>



--
Thomas A. Russ, USC/Information Sciences Institute

 
 
mearvk





PostPosted: 2008-3-11 18:03:00 Top

java-programmer >> CubicCurve2D Tracing On Mar 10, 11:01燼m, Daniel Pitts
<email***@***.com> wrote:
> mearvk wrote:
> > On Mar 8, 12:29 pm, Daniel Pitts
> > <email***@***.com> wrote:
> >> mearvk wrote:
> >>> Given an arbitrary CubicCurve2D how can I iterate along it getting
> >>> both the x and y coordinates of the current point as I go?
> >>> Thanks.
> >> Try: calling getPathIterator on it.
> >> <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Shape.html#getPathIt....)>
>
> >> --
> >> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
>
> > Looking at the API I think PathIterator's currentSegment() will just
> > get me the beginning, end and both control points. What I need is a
> > way to, for instance, find the length of or iterate over, pixel by
> > pixel, an arbitrary bezier curve. What I am actually doing is trying
> > to find the shortest path along a pair of bezier curves (think race
> > track) using a third bezier curve (think finding the apex). But how to
> > grade the quality of the current best path? Surely the simplest thing
> > to do would be to ask how long is the line? I was thinking if there
> > were a way to map the start, end, and both control points onto a
> > mathematical function, then I could just scale it appropriately and
> > iterate pixel by pixel, summing as I go, but I'm not sure if this can
> > be done.
>
> This might help:
> <http://java.sun.com/j2se/1.4.2/docs/api/java/awt/geom/FlatteningPathI...>
>
> Also, Bezier curves are well defined mathematically, there is quite
> likely a formula to find the length given the endpoints and control points..
>
> A quick google turned up:
> <http://www.cit.gu.edu.au/~anthony/info/graphics/bezier.curves>
>
> Its actually an integral, so you are going about it in a reasonable way.
> ?FlatteningPathIterator is what you want. Just sum the distance between
> any two endpoints it gives you.
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>- Hide quoted text -
>
> - Show quoted text -

Thank you both.