0

I'm doing some computer graphics program. I need to draw a bezier curve and then determine if a point is on this curve. I've defined 4 points(2 endpoints, 2 control points) and plotted a bezier curve using DrawBeziers. So how can I determine if a point is on the drawn curve?

  • Should I get all the points on the Bezier curve and check if a point in all points of the curve?
  • Should I get the equation of the curve and check a point can make the equation true?
  • Should I use DrawBeziers method to draw it?

How can I implement this feature?

I'm looking forward to everyone's answers, it would be better if the answers could be explained in detail. Thanks in advance.

  • 1
    If you use `GraphicsPath.AddBezier()` or `GraphicsPath.AddBeziers()`, then of course draw the Path with`e.Graphics.DrawPath([Pen], [GraphicsPath]);`, you can use the [GraphicsPath.IsOutlineVisible()](https://learn.microsoft.com/en-us/dotnet/api/system.drawing.drawing2d.graphicspath.isoutlinevisible) method to determine whether the drawn Bezier outline contains a `PointF`. This method doesn't consider anti-aliasing, only the size of the Pen. – Jimi Jul 29 '22 at 12:48

1 Answers1

1

I would assume that the goal is to check if the user clicked on the curve or not. The mathematical curve will be infinitely thin, so what you really are after is to compute the distance to the curve. The link provides the math. Once you have the distance, just check if it is lower than the line thickness.

A potentially more accurate way would be to draw the curve, and any other graphics to a internal bitmap, using a unique color for each object, and without any anti-aliasing. That will give you an easy way to lookup the clicked object, while supporting overlapping shapes in a natural way. Also consider using a wider line-thickness when drawing to make it easier to select objects. But it will be somewhat costly to redraw the internal bitmap.

Another alternative would be to convert your spline into a polyline, and check the distance to each line segment. This is probably least accurate, but should be very simple to implement if you already types for line segments.

JonasH
  • 28,608
  • 2
  • 10
  • 23