View Full Version : Length of quadratic curve?
Calculating the length of a a straight line is simple, using ol Pythagoras theorem.
But how do you calculate the length of a quadratic curve? I've searched around quite a lot for this on google and forums but haven't found anything useful yet..
I don't need it to be 100% accurate, mainly I want to use it to draw a shape consisting of both straight lines and curves, but I want to draw it all in a consistent speed, at least so the viewer doesn't see that the speed changes.
Thanks in advance..
remisc
05-05-2008, 02:35 PM
It's just my idea. Don't judge hard on me, I am not very at geometry (or english)
I believe you can use here linear aproximation of curve and some kind of numeric method since you don't need exact length.
My idea uses divide and conquer algorithm family and it is quite straightforward.
Lets say you have function y = f(x) , f - your curve. x0, xn - your first and last points on x axis respectivelly. calcule distance (L1) between point (x0, y0) and (xn, yn) (aproximate your curve to straight line for 2 points). Now take point some on the middle in curve xm, calcule ym, calcule and sum distance between (x0, y0) and (xm, ym), (xm, ym) and (xn, yn). L2 = d((x0, y0) , (xm, ym)) + d((xm, ym) (xn, yn)). If difrence between L1 and L2 is insignificant then stop (delta > L1 - L2), else continue recursevly dividing.
I think this way you can get pretty accurate result. But recursion is evil :]
More simple way to do this is to use fixed segment's points. Just use some defined amount of points on x axis, and aproximate your curve to lines between these segments. Not so accurate, but I believe you will achieve better performance.
I hope you will understand that i suggest :]
EDIT:
Something that I found on forums about length of bezier curves. http://www.gamedev.net/community/forums/topic.asp?topic_id=313018
Yeah, I understand. Thanks for your advices =)
I was already thinking about using your second suggestion, and I think I will do that, however if I need to measure a curve again later and need more precision and performance is less important then I will use your fist advice which i hadn't thought of before =)
More advices are still welcome
Thanks
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.