Hi all,
I would like to know if there's a way of evaluating if a point is inside a closed curve.
At the moment I haven't found nothing similar in the forum,
can anyone help me?
Thank you,
J
A smooth curve can always be approximated with straight lines, the shorter the lines the smoother the shape will be. :)
If you have straight lines then the solution is straight forward. Select any point that is outside the shape, easy enough pick one withh extremely large x and y coordinates [ox,oy]
Now to test a point [x,y] to see if it inside the shape test the line [x,y]-[ox,oy] and see how many lines in the shape it intersects with (n)
If n is odd then the point [x,y] is inside the shape if even it is outside the shape. Note zero is even.
Thanks quark,
I started working on that but I can't figure out how to evaluate the intersection between two lines and I haven't found examples yet..can you suggest me something?
Thanks again
Answers
Is the curve smooth or made from straight lines?
At the moment the curve is smooth but eventually I can try to find a way of approximate it with straight lines
A smooth curve can always be approximated with straight lines, the shorter the lines the smoother the shape will be. :)
If you have straight lines then the solution is straight forward. Select any point that is outside the shape, easy enough pick one withh extremely large x and y coordinates [ox,oy]
Now to test a point [x,y] to see if it inside the shape test the line [x,y]-[ox,oy] and see how many lines in the shape it intersects with (n)
If n is odd then the point [x,y] is inside the shape if even it is outside the shape. Note zero is even.
Thanks quark, I started working on that but I can't figure out how to evaluate the intersection between two lines and I haven't found examples yet..can you suggest me something? Thanks again
This webpage might help. Goto page 6 and you are looking foe intersection of 2 finite lines. There are loads more like this on the web.
That's exactly what I was looking for..thanks a lot