Re: Intersection of bezier and straight line
- From: praveenk.dj@xxxxxxxxx
- Date: 20 May 2007 22:15:18 -0700
On May 19, 12:02 pm, "Dave Eberly" <dNOSPAMebe...@xxxxxxxxxxxxxxx>
wrote:
<yogesh.k...@xxxxxxxxx> wrote in message
news:1179495050.245414.248160@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I was wondering, how do we determine the a value 'Y' on a bezier when
you know the value of X coordinate.
ie. for X = (say) 10.0 , how do we find corrosponding Y value.
This problem reduces to finding intersection of line X=10 with the
given bezier.
If the curve is (x(t),y(t)) and the vertical line is x = x0, you need
to compute the roots to the polynomial p(t) = x(t) - x0. For each
root T, compute the y-value y(T).
As mentioned by another poster, if the curve is degree 3, then you
could use the closed-form equations for the roots to a cubic. Be
aware, though, that those equations are notoriously ill-conditioned
when you have two roots that are nearly the same.
Also I was wondering if it is possible to achive this using Dave
Eberly's Wild Magic library.
By example:
int Generic::Main (int, char**)
{
// The Bezier curve is
// (x(t),y(t)) = (1-t)^3*P0 + 3*(1-t)^2*t*P1 + 3*(1-t)*t^2*P2 + t^3*P3
// for 0 <= t <= 1.
const int iDegree = 3;
Vector2d* akCtrlPoint = WM4_NEW Vector2d[iDegree + 1];
akCtrlPoint[0] = Vector2d( 0.0,0.0);
akCtrlPoint[1] = Vector2d( 3.0,1.0);
akCtrlPoint[2] = Vector2d(-1.0,2.0);
akCtrlPoint[3] = Vector2d( 4.0,4.0);
BezierCurve2d kCurve(iDegree, akCtrlPoint);
// The polynomial x(t).
Polynomial1d kXPoly(iDegree);
kXPoly[0] = kCurve.GetPosition(0.0)[0];
kXPoly[1] = kCurve.GetFirstDerivative(0.0)[0];
kXPoly[2] = kCurve.GetSecondDerivative(0.0)[0]/2.0;
kXPoly[3] = kCurve.GetThirdDerivative(0.0)[0]/6.0;
// The vertical line x = x0.
double dX0 = 1.26;
// Solve for x(t) = x0.
kXPoly[0] -= dX0;
int iDigits = 8;
PolynomialRootsd kPR(Mathd::ZERO_TOLERANCE);
kPR.FindB(kXPoly,iDigits);
// I have chosen the curve and an x0 so that the vertical line
// intersects the curve 3 times.
int iCount = kPR.GetCount();
const double* adRoot = kPR.GetRoots();
// root[0] = 0.33563439076802315
// root[1] = 0.42569287040671300
// root[2] = 0.55117273179554338
double dY0 = kCurve.GetPosition(adRoot[0])[1];
double dY1 = kCurve.GetPosition(adRoot[1])[1];
double dY2 = kCurve.GetPosition(adRoot[2])[1];
// y0 = 1.0447125355351101
// y1 = 1.3542202977928879
// y2 = 1.8209597203487196
return 0;
}
--
Dave Eberlyhttp://www.geometrictools.com
Hi Dave,
Am very very impressed by looking at this post.I am very much
intersted in the way you would actually be finding the intersection
points of a bezier and a straight line.I would love to know how the
polynomial equation is created using the bezier contol points and then
how are the roots actually calculated using the 1st,2nd and third
derivatives of the polynomial.Could you give me a little insight into
this
Thanks and Regards
Praveen
.
- Follow-Ups:
- Re: Intersection of bezier and straight line
- From: Dave Eberly
- Re: Intersection of bezier and straight line
- References:
- Intersection of bezier and straight line
- From: yogesh . kini
- Re: Intersection of bezier and straight line
- From: Dave Eberly
- Intersection of bezier and straight line
- Prev by Date: Re: Intersection of bezier and straight line
- Next by Date: Re: Intersection of bezier and straight line
- Previous by thread: Re: Intersection of bezier and straight line
- Next by thread: Re: Intersection of bezier and straight line
- Index(es):
Relevant Pages
|
Loading