![]() |
|
|
|||
|
[.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 |
|
|||
|
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. |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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. |
|
|||
|
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 |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|