Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position of a point relative to a Bezier curve

I have a Bezier curve specified by 4 points. I need to know if a point is on the left side or right side of the Bezier curve. Can you suggest me an algorithm?

Edit: I'm sure that the way I generate the Bezier curve would not form loops.

Later edit I realized that my initial problem could be solved without using relative position. When I posted this question I was thinking that there is a mathematical formula for relative position similarly with checking if a point is in the interior of a circle. It seems that this is not possible. So I will accept the answer which will suggest a time efficient solution.

like image 697
Ionel Bratianu Avatar asked May 28 '09 12:05

Ionel Bratianu


2 Answers

You can determine the closest point on the bezier curve with a pretty straightforward algorithm (related to k-subdivision. DeCastleju's Algorithm.) Look at the graphics gems if you need specifics.

At that point, even with loops, you can determine side-ness by determining if the vector to your tested point from the closest point is on the left of right hand of the vector that goes along the curve (velocity? - not sure of the correct term here...) of the bezier at the closest point you determined.

You can get -that- by cross product of the two vectors. Negative or positive will determine the handedness and which side of the line you are on.

Of course, in a loop the sideness will be defined as if you were a car driving down the line, would you be looking out the right or left window at the point as you go by... Not if you are to the right or left of the whole bezier squiggle. So it depends on how you define "sideness"

Sorry if my terms are off. Its been awhile since I had to do anything with Bezier's

It would be easier to draw a picture ;)

like image 131
Jeremy White Avatar answered Sep 28 '22 04:09

Jeremy White


If you just want your object to follow the curve (as you say in your comment), why don't you just move your object with the parametric equation ? See this article

like image 41
rockeye Avatar answered Sep 28 '22 03:09

rockeye