Wednesday, July 23, 2008

Checking a point inside Quadratic curve

In the last post I had written about qudratic equation. After that one thought came to my mind is How to check a point inside the curve ?. 

Below shows the qudratic curve equation from our 3 points. t^2(p1-p0'-p0) + p0' * t + p0 = P.  P is a point on the curve corresponding to t.

That is  a*t^2 + b* t + c = p, where a,b,c ,p are vectors. p yields the points on the curve accoding to the 't'.

So how can we check a point is in curve or not ?  we have 'p' and equation of the curve.As you guess this can be done by equation solving.But here a,b,c, are vectors.

So there must be some way to produce scalar values from these vetors , like taking magnitude of vectors in the equation like 

     |a|*t^2 + |b|*t + |c| = |p|.

This equation has some problmes , because it is just looking the magnitude of the vectors , direction is missing.A More wiser solution may be to solve for X,Y (Z in 3D)independently,like

a.x* t^2 + b.x *t + c.x = p.x --------> (1)

a.y* t^2 + b.y *t + c.y = p.y --------> (2)

As we know when we draw curve from p0 to p1 the t will vary from 0 -1 , We can check a point is inside the curve by solving one equation ( example : equation 1 ) and substitute that value of t in other equation ( here in equation2 ) . If you got the correct result as that of the input point (res == p.y) you can say the point is in the curve. Otherwise not.

When you solving the above equation you will get two values of t , so take the value which is inbetween 0 and 1 , and susbstitue it in other equation. 

To solve linear equation in computer you can use gauss elimination method ( you can try the above method in matheamtica easily ). 

No comments: