How to get coordinates of some area

51 Views Asked by At

I have a rectangle and I divide it into 8 triangle with same size. Top left corner is origin. I want to check that if a point is inside the black area or not. Lets say point's x coordinate is pointX and y coordinate is pointY.

I just know that for bottom left area pointX < (width / 2) and pointY > (height / 2). Is there any idea?

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

In the posted picture, the lines denoting the various areas of consideration do not align with exact horizontal, vertical or $\pm 45^\circ$ sections, but with a width $w$ not necessarily equal to the height $h$, this is to be expected.

To limit a point within one of the described areas, this difference between width and height must be addressed beyond my commented suggestion as follows:

  • For areas next to the line going "up and to the right" we are considering the line $y=h-\frac hw\cdot x$
  • For areas next to horizontal (or vertical) lines, we are considering the line $y=\frac h2$ (or $x=\frac w2$)
  • For areas next to the line going "down and to the right" we have the line $y=\frac hw\cdot x$

Taking this, the requested area is "greater than" the "up and to the right" line and "less than" the $x=\frac w2$ line, giving us the conditions

$$x\lt \frac w2\\y\gt h-\frac hw\cdot x$$