CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   To find whether a point lies inside or outside a curve defined by points (https://www.cfd-online.com/Forums/main/162042-find-whether-point-lies-inside-outside-curve-defined-points.html)

casper November 2, 2015 05:40

To find whether a point lies inside or outside a curve defined by points
 
Hello all,

I have a closed curve defined by points and not equation. I have find if a point lies inside the curve or outside. Is there a way to do this without having to fit an equation to the curve?
Here by points I mean computational nodes and the points on the curve need not coincide with the nodes.

JulianP November 2, 2015 07:25

Hello,

have a look here: https://en.wikipedia.org/wiki/Point_in_polygon

In short: Draw an infinite horizontal line in one direction beginning at the point in question. Now, count how often this line intersects the edges of the polygon. If you get 0 or an even number, the point lies outside. If you get an odd number, the point lies inside.

You only have to think about what happens when your point lies on an edge of the polygon.

casper November 2, 2015 23:53

Hey,

This would be easy if we had the equation of the curve. In my case, the curve is defined by points and cannot be very easily fit into an equation.

JulianP November 3, 2015 02:35

Hello casper,

this is a point-in-polygon test. In a polygon the discrete points are connected by edges, which are simple straight lines.

Have a look here: https://www.ics.uci.edu/~eppstein/161/960307.html You can find some pseudo-code there.

Don't think too complicated :)

casper November 3, 2015 03:48

Thats awesome! Also the link has detailed description for the procedure.
Thanks Julian :D


All times are GMT -4. The time now is 09:08.