471,306 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Point into a ClosedCurve

Hello,

I'm developing an application that manages some kind of shapes.
One of those shapes is an drawn using Graphics.DrawClosedCurve() function.
I want to know if the user has selected a coordinate inside this draw or
not, but I don't know how to do it. Any idea?

Thank you
Jan 24 '06 #1
4 2049
Sergio,

Take a look at the GraphicPath and Region classes. You can add closed
curves to an instance of the GraphicPath and then add the GraphicPath to an
instance of a Region class. Afterwards, you can use the region's IsVisible
method to find a point within the it.

I don't use this objects, so I may be a little off on their use; however, I
don't think I am.

If you looking for points in a polygon, I translated a class from C++ to C#
to do that; however, you are using curves so it won't help you there.

At any rate, I hope I have helped.
Dave
Jan 24 '06 #2
GraphicsPath is enough for hittesting. It contains method IsVisible and
IsOutlineVisible. The latter is to check only on the path outline. Graphics
path is very useful type. I won't suggest using Regions though. Besides they
are resource expensive the type also has bugs that cause memory leaks IFAIK
(at least in .NET 1.x)

--

Stoitcho Goutsev (100)

"D. Yates" <fo****@hotmail.com> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl...
Sergio,

Take a look at the GraphicPath and Region classes. You can add closed
curves to an instance of the GraphicPath and then add the GraphicPath to
an instance of a Region class. Afterwards, you can use the region's
IsVisible method to find a point within the it.

I don't use this objects, so I may be a little off on their use; however,
I don't think I am.

If you looking for points in a polygon, I translated a class from C++ to
C# to do that; however, you are using curves so it won't help you there.

At any rate, I hope I have helped.
Dave

Jan 24 '06 #3
Stoitcho Goutsev (100) wrote:
GraphicsPath is enough for hittesting. It contains method IsVisible and
IsOutlineVisible. The latter is to check only on the path outline. Graphics
path is very useful type. I won't suggest using Regions though. Besides they
are resource expensive the type also has bugs that cause memory leaks IFAIK
(at least in .NET 1.x)


Thank you to both. I've solved my problem using GraphicsPath and
IsVisible().
Jan 25 '06 #4
IsVisible and IsOutlineVisible are both also broken when using float
types. If you are working in integer pixels, you should be ok.

Broken? Yeah...

GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0.0f, 0.0f, 0.0625f, 0.0625f));

// defintely outside the path
if (path.IsVisible(-0.01f, -0.01f))
{
throw new ApplicationException("This is crazy");
}
}

Microsoft claims this is "as designed" with vauge reference to
GraphicsPath rasterizing before testing.

If you want try testing with floats you have to write your own code to
make use of PathData. If you are working with curves, you canto
flatten before working with PathData.

Generally speaking to test "am i inside" a closed path, project a
vector from testing point to somewhere outside of the path (anywhere).
Then count intersections between test vector and the line segments that
comprise the flattened path. If count is odd, the point is inside the
closed path. If the count is even, the point is outside the closed
path.

To test "am I on the path", compute the length of the normal for each
line segment in the flattened path and then test if the length of the
normal is within some tolerance (such as pen width).

Sergio wrote:
Stoitcho Goutsev (100) wrote:
GraphicsPath is enough for hittesting. It contains method IsVisible and
IsOutlineVisible. The latter is to check only on the path outline. Graphics
path is very useful type. I won't suggest using Regions though. Besides they
are resource expensive the type also has bugs that cause memory leaks IFAIK
(at least in .NET 1.x)


Thank you to both. I've solved my problem using GraphicsPath and
IsVisible().


Jan 25 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Roger Leigh | last post: by
5 posts views Thread by Anton Noll | last post: by
687 posts views Thread by cody | last post: by
3 posts views Thread by Action | last post: by
39 posts views Thread by DanielJohnson | last post: by
39 posts views Thread by rembremading | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.