I want to be able to check if a list of points will hit a screwed rectangle (rhombus i think).

I start out with 2 point P and T, i want to create a rectangle between the 2 points. I have used https://stackoverflow.com/questions/7854043/drawing-rectangle-between-two-points-with-arbitrary-width to do this. This gives me 4 points A, B, C and D of the new rectangle.

I then want to check if the point M is withing this rectangle.

enter image description here The two black dots are my points P and T, the black box is the rectangle i want to generate between the two dots, being X wide. I then want to test if the red dots are withing the black box.

  • 1
    \$\begingroup\$ So is there a question you wanted to ask? \$\endgroup\$ – Tyyppi_77 May 9 '16 at 5:02
  • \$\begingroup\$ @Tyyppi_77 "I then want to check if the point M is withing this rectangle." But see my updated question \$\endgroup\$ – Androme May 9 '16 at 5:39

There are lots of algorithms to check whether a point is inside or outside a polygon. The simplest being the ray casting algorithm.

The idea is, you cast a ray (assume a line) from your point to either the left or the right. Then for each side of your polygon, you test whether the ray intersects it, and if it does, you add 1 to a counter. At last, if the number of times the ray intersected with a side is odd (that is if counter % 2 == 1), your point lies inside the polygon.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.