wenz
wenz

Reputation: 31

Find if point lies on Bezier line created By DrawBezier function

I have Bezier line created by C# DrawBezier function with four points S(x1,y1), E(x2,y2), C1(x3,y3), C2(x4,y4). The S and E are endpoints, and C1 and C2 are control points. How can I check if the point p(x,y) lays on the Bezier line?

Upvotes: 0

Views: 345

Answers (1)

TaW
TaW

Reputation: 54463

Doing so analytically in math is rather hard, but the built-in GDI+ methods come to the rescue..:

Create a GraphicsPath that is exactly the same and use the GraphicsPath.IsVisible(Point) method

 using System.Drawing.Drawing2D;
 ..

Lets assume you draw your bezier curve like this:

 e.Graphics.DrawBezier(yourPen, yourParameterList );

Then this will tell you if a point lies on it:

 GraphicsPath gp = new GraphicsPath();
 gp.AddBezier(yourParameterList);
 if (gp.IsVisible(yourPoint)) .. //do your stuff;

And of course you can replace the DrawBezier by a DrawPath:

 e.Graphics.DrawPath(yourPen, gp);

Upvotes: 3

Related Questions