How to decide if a Point is on a curve
-
I draw a curve using the DrawCurve method. I also want to have some kind of interaction with the curve when moving the mouse over it. Could someone show me how to decide if a Point is on the curve? Thanks!
Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the
Region
andGraphicsPath
classes.Region
is found inSystem.Drawing
andGraphicsPath
is inSystem.Drawing.Drawing2D
. 1.DrawCurve
to screen 2. Create aGraphicsPath
and draw to it. 3. Create aRegion
from theGraphicsPath
. 4. InvokeIsVisible( somePoint )
on theRegion
. In this casesomePoint
would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature? -
Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the
Region
andGraphicsPath
classes.Region
is found inSystem.Drawing
andGraphicsPath
is inSystem.Drawing.Drawing2D
. 1.DrawCurve
to screen 2. Create aGraphicsPath
and draw to it. 3. Create aRegion
from theGraphicsPath
. 4. InvokeIsVisible( somePoint )
on theRegion
. In this casesomePoint
would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature? -
Hello, The way I have seen this done was in a project I worked on in a group for school. Check out the
Region
andGraphicsPath
classes.Region
is found inSystem.Drawing
andGraphicsPath
is inSystem.Drawing.Drawing2D
. 1.DrawCurve
to screen 2. Create aGraphicsPath
and draw to it. 3. Create aRegion
from theGraphicsPath
. 4. InvokeIsVisible( somePoint )
on theRegion
. In this casesomePoint
would be your mouse point. Hope this helps, Nathan --------------------------- Hmmm... what's a signature?There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!
-
There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!
Hmmm.... I don't know how to fix that problem right off had. You will have to look through the documentation some more. I am sorry that this did not solve the problem exactly. Please post here again if you find a solution. Sorry, Nathan --------------------------- Hmmm... what's a signature?
-
There is a problem with this method. Though the curve is a open end curve, the region seems like a closed region. IsVisible returns true not only when the mouse is over the curve but also inside the region enveloped by the region. Have you encountered the same problem? How did you resolve it? Thanks!
I found the same problem as above and your description of the problem helped to give me the answer. If the path is closed already, the path.IsVisible(point) should work. To keep the line as pure looking as possible using pixels, just reverse the points in the array and add them to the original set. Then add them to a closed curve in the path.
GraphicsPath _curvePath = new GraphicsPath(); List<PointF> closedCurvePoints = new List<PointF>(_curvePoints); closedCurvePoints.Reverse(); closedCurvePoints.AddRange(_curvePoints); _curvePath.AddClosedCurve(closedCurvePoints.ToArray());
This worked well for me - even for curves that backed in on themselves. Hopefully it will be helpful to someone else if you have no need for this info anymore