I'm not very comfortable with math.. what I'm trying to do is to find a point at the 1/4 length of a Bezier curve, with one control point, ie QuadCurve2D. I don't know which thing I should use and how, for instance "solveQuadratic" is static, and thats a pity, because I don't know what parameters to pass! "subdivide" looks useful, hmm, heh, it seems I just found a solution, to subdivide 2 times and get the end-points of the new curves. But what if I needed a point at 3/5 of the curve?
All help is most warmly appreciated, thanks
Alright, you're not being comfortable with math isn't quite the greatest approach to this problem, but I'll try to explain it anyways. Finding the length of a quadratic (parabolic) curve takes some calculus. The equation for Arc-Length of any curve is the definite integral between the starting and ending points of your arc (curve) of the square root of one plus the equation of the curve's derivative squared.
Like this: http://archives.math.utk.edu/visual.calculus/5/arclength.1/
I'll start working on some source code for this problem...
Alright, you're not being comfortable with math isn't
quite the greatest approach to this problem, but I'll
try to explain it anyways. Finding the length of a
quadratic (parabolic) curve takes some calculus. The
equation for Arc-Length of any curve is the
definite integral between the starting and ending
points of your arc (curve) of the square root of one
plus the equation of the curve's derivative squared.
Like this:
http://archives.math.utk.edu/visual.calculus/5/arclengt
.1/
I'll start working on some source code for this
problem...
It seems what I meant by "length" was misunderstood, I was trying to find a point at the quarter of the curve, so that I could display some info there. By the way, here is what Bezier curves are:
http://astronomy.swin.edu.au/~pbourke/curves/bezier/
If you are messing with curves, check that out and the classes I mentioned, they are very cool and useful (although I feel you already know)
Though many people think that programming is tightly coupled with math.. I strongly disagree! When I can afford it, I'm thinking hiring a mathematician for this sort of problems!! Ok, discrete math is a big exception.
Thanks for your interest! :-)
ps: I find those math you linked very, very
incomprehensible! :-S
Math programming is cool. I'm doing someting similar but do not use Bezier curve because they do not interpolate. I use cubic splines, or polynomials if points are close.
Hi, i found this in Computer Graphics for Java Programers, by Leen Ammeraal. Excellent book!
Anyway this is a B-Spline drawing method, i used it in a path tool for a level editor. I hope you don't have to use Bezier curves.
publicvoid bspline(Graphics g){
g.setColor(Color.red);
int n = points.size();
int xA, yA, xB, yB, xC, yC, xD, yD,
a0, a1, a2, a3, b0, b1, b2, b3, x=0, y=0, x0, y0;
double time_delta = 0.01; // this chooses how many point to go trough the curve, smaller number, more points.
double xd0= 0;
double yd0 = 0;
double xd1= 0;
double yd1 = 0;
double x_delta = 0;
double y_delta = 0;
boolean first = true;
for (int i=1; i<n-2; i++) { // Loop Through Control Points
iPoint2D p0 = (iPoint2D)points.get(i-1);
iPoint2D p1 = (iPoint2D)points.get(i);
iPoint2D p2 = (iPoint2D)points.get(i+1);
iPoint2D p3 = (iPoint2D)points.get(i+2);
xA=p0.x;
xB=p1.x;
xC=p2.x;
xD=p3.x;
yA=p0.y;
yB=p1.y;
yC=p2.y;
yD=p3.y;
a3=(-xA+3*(xB-xC)+xD)/6;
b3=(-yA+3*(yB-yC)+yD)/6;
a2=(xA-2*xB+xC)/2;
b2=(yA-2*yB+yC)/2;
a1=(xC-xA)/2;
b1=(yC-yA)/2;
a0=(xA+4*xB+xC)/6;
b0=(yA+4*yB+yC)/6;
for (double t=0; t<=1.0; t+=time_delta) { // Go from start to end of curve
x0 = x; y0 = y;
double x1 = ((a3*t+a2)*t+a1)*t+a0;
double y1 = ((b3*t+b2)*t+b1)*t+b0;
x = (int)Math.round(x1);
y = (int)Math.round(y1);
if (first){
first = false;
}
else{
g.drawLine(x0, y0,x , y);
}
}
}
}
The main loop goes from T=0 > T=1, so at T=0.25 you 1/4 trough the curve.
Now im like you, not that good at math, but working on it!
So there might be a more effective solution. Though i know this will work.
Hope that helps!
Harley.
Plus here is the link to the complete examples
http://home.wxs.nl/~ammeraal/software/English/grjava.zip
Amazon book link
http://www.amazon.com/exec/obidos/ASIN/0471981427/qid%3D1033446353/sr%3D11-1/ref%3Dsr%5F11%5F1/103-6165914-4071849
Hi Harley,
Thanks a lot for your reply! I just read it. From my point of view, one that isn't particularly interested in math should stay away and look for practical solutions! "Practical" i mean...short and even dirty ones :) I did the dirty trick I said above, using QuadCurve2D.subdivide I cut the curve at halves and get the 1/4 point I needed.
The main loop goes from T=0 > T=1, so at T=0.25 you 1/4 trough the curve.
surely this holds true? If it does, then it would be a wonderful property for these curves, though I fear not. Couldn't the points just be like this? :
..... . . . . . . .
1/4 point here would not really be at the 1/4 of the distance..!
Kind regards
Dimitris
Hey i do agree with you, its best to go with the simpelest solution to the problem, so if using QuadCurves solves your problem use it.
The main issue would be you don't control how the curve is solved, does it interlopate the control points, and how do multiple curve segements join? The other point would be speed, i had to use b-spline curves for a game, using QuadCurves would not be fast engouh.
Back to your question does it really work, the main loop is like for(double t=0; t<=1; t+=delta)
if you increase delta you'd get 1/4 the points. stoping at t=.25 would be 1/4 through the curve. i think the only catch is that it'd only work with curve <= 4 control points.
I also found a simple bezier method, which would solve your problem with less code, but does not interlopate control points like b-splines.
I'll put it up if you want.
Hey i do agree with you, its best to go with the
simpelest solution to the problem, so if using
QuadCurves solves your problem use it.
The main issue would be you don't control how the
curve is solved, does it interlopate the control
points, and how do multiple curve segements join? The
other point would be speed, i had to use b-spline
curves for a game, using QuadCurves would not be fast
engouh.
Back to your question does it really work, the main
loop is like for(double t=0; t<=1; t+=delta)
if you increase delta you'd get 1/4 the points.
stoping at t=.25 would be 1/4 through the curve. i
think the only catch is that it'd only work with
curve <= 4 control points.
I also found a simple bezier method, which would solve
your problem with less code, but does not interlopate
control points like b-splines.
I'll put it up if you want.
How are you using the curves?
Id always say experiment!
Later, Harley.
Don't worry, I know I control almost nil about the curves, but it doesn't really matter, nor it's for some real-time environment, it's a graph application for educational purposes, and if two nodes are bi-connected with each other, then a straight line for the edge is not too good. The problem was to find a point, at the curve, where I can print some info (say cost of it) about the edge, which is easy at straight edges.
As you may see, it is too minor issue to go and dust my math books from the self!
If u like experimentation, and have or are willing to download shochwave 5, check this out! http://www.moshplant.com/direct-or/bezier/
It's amazing these curves can be used in animation. Really inspiring!
Bye bye,
Dimitris
Hi.
Sorry to come in late in the discussion but I've just completed a grapher to plot algebraic functions and it uses Bezier curves - it calculates the four control points for a CubicCurve2D so it can be used to plot straight lines, quadratics and cubics.
If you're interested let me know which bits of code you want (there's quite a lot of other stuff in the 1500 lines of code, ie axes drawing, autoscaling etc)
Its amazing how many thing you can use curves for! Mainly interested in curved surfaces, and motion.
The last project i did broke down a b-spline into x,y steps that equaled the desired speed. You only need to object.x += curve.nextX() to move through.