Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > .NET Framework

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-17-2008, 08:46 AM
Oriane
 
Posts: n/a
[.Net 3.0]Point inside a polygon

Hi there,

I'm looking for a boolean method the result of which is true if a 2D point
is *inside* a polygon - anf false otherwise. I suppose that this is existing
in the WPF class like PointCollection, but I can't find it.

Oriane

Reply With Quote
  #2 (permalink)  
Old 07-17-2008, 09:53 AM
Linda Liu[MSFT]
 
Posts: n/a
RE: [.Net 3.0]Point inside a polygon

Hi Oriane,

You can get the geometry of the Polygon through its RenderedGeometry
property and call the FillContain(Point) method on the returned geometry
object to detect whether the geometry contains the specifed point or not.

The following is a sample:

Geometry geo = this.polygon.RenderedGeometry;
bool result = geo.FillContain(new Point(20,20));

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply With Quote
  #3 (permalink)  
Old 07-17-2008, 01:18 PM
Oriane
 
Posts: n/a
Re: [.Net 3.0]Point inside a polygon

Thank you Linda. I will try...
Reply With Quote
  #4 (permalink)  
Old 07-21-2008, 01:26 AM
Linda Liu[MSFT]
 
Posts: n/a
Re: [.Net 3.0]Point inside a polygon

Hi Oriane,

How about the problem now? Have you had a chance to try my suggestion?

If you have any question, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Reply With Quote
  #5 (permalink)  
Old 07-22-2008, 09:59 AM
Oriane
 
Posts: n/a
Re: [.Net 3.0]Point inside a polygon

Hi Linda,
"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> wrote:
news:HnDHXDt6IHA.3320@TK2MSFTNGHUB02.phx.gbl...
> How about the problem now? Have you had a chance to try my suggestion?


Yes but I just realize that this code:

**************************************
System.Windows.Shapes.Polygon p = new Polygon (...);
Geometry geo = p.RenderedGeometry;
**************************************
does not work (at least for me) since the geo object has empty Bounds... The
p object is not empty and filled with these points: Points {29,61;62,94
35,5;62,94 35,5;57,1 29,61;57,1}. So I don't really see what to do.

A very exciting point about WPF is that it provides us with a mathematicl
library (at least for vector calculus), and I just discover that this code
is possible:

void OneStepTowardGoal ( Point3D goal, Point3D currentPos, double dT)
{
Vector v = goal - currentPos;
v.Normalize();
Vector deltaV = v * speed * dT;
this.currentPos += deltaV;
}

which is exactly what I look for.

Best regards


Reply With Quote
  #6 (permalink)  
Old 07-23-2008, 10:08 AM
Linda Liu[MSFT]
 
Posts: n/a
Re: [.Net 3.0]Point inside a polygon

Hi Oriane,

Thank you for your reply!

> ...The p object is not empty and filled with these points: Points

{29,61;62,94 35,5;62,94 35,5;57,1 29,61;57,1}.

You may try the following code snippet to see if the problem can be solved:

PathGeometry pathGeo = new PathGeometry();
PathFigure pathFigure = new PathFigure();
PolyLineSegment seg = new PolyLineSegment();
PointCollection ponts = new
PointCollectionConverter().ConvertFromString("62,9 4 35,5 62,94 35,5 57,1
29,61 57,1") as PointCollection;
seg.Points = ponts;
pathFigure.StartPoint = new Point(29, 61);
pathFigure.Segments.Add(seg);
pathGeo.Figures.Add(pathFigure);
bool r =pathGeo.FillContains(new Point(-10, -10));
r = pathGeo.FillContains(new Point(0, 0));

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Reply With Quote
  #7 (permalink)  
Old 07-24-2008, 02:23 PM
Oriane
 
Posts: n/a
Re: [.Net 3.0]Point inside a polygon


"Linda Liu[MSFT]" <v-lliu@online.microsoft.com> a écrit dans le message de
news:UvUubwK7IHA.1624@TK2MSFTNGHUB02.phx.gbl...
> Hi Oriane,
>
> Thank you for your reply!
>
>> ...The p object is not empty and filled with these points: Points

> {29,61;62,94 35,5;62,94 35,5;57,1 29,61;57,1}.
>
> You may try the following code snippet to see if the problem can be
> solved:
>
> PathGeometry pathGeo = new PathGeometry();
> PathFigure pathFigure = new PathFigure();
> PolyLineSegment seg = new PolyLineSegment();
> PointCollection ponts = new
> PointCollectionConverter().ConvertFromString("62,9 4 35,5 62,94 35,5 57,1
> 29,61 57,1") as PointCollection;
> seg.Points = ponts;
> pathFigure.StartPoint = new Point(29, 61);
> pathFigure.Segments.Add(seg);
> pathGeo.Figures.Add(pathFigure);
> bool r =pathGeo.FillContains(new Point(-10, -10));
> r = pathGeo.FillContains(new Point(0, 0));
>
> Hope this helps.

Indeed it has helped !

Thanks

Oriane

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > .NET Framework


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:09 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108