N
N
nimbus2142021-09-28 13:44:39
Mathematics
nimbus214, 2021-09-28 13:44:39

How to find whether a point belongs to a shaded area on a plane?

coordinates are only positive (it turns out this is only the first quarter of the entire plane), the plane itself is infinite.
6152f1df93d25008722385.jpeg

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wataru, 2021-09-28
@wataru

Separately, check that the dot is in the first quarter.
Further, the figure is repeated in 2x2 blocks, i.e. you don't care about the coordinates themselves, only their position in the block.
To calculate a coordinate in a block, you can either subtract 2 while the coordinate is greater than 2, or subtract from x (floor(x) - floor(x)%2). floor(x) will give integers. Then we need to make this number even, it is possible to subtract 1. floor(x)%2 - just gives us what to subtract.
And then - a set of if-s. you only need to describe that the point belongs to one of the two quadruples of the circle in the lower left corner.

A
Alexandroppolus, 2021-09-28
@Alexandroppolus

In, this is already cool)
squares - 1x1?
offhand like this:

if (Math.ceil(y) % 2 && !(Math.floor(x) % 2)) {
  return ((x - Math.floor(x)) ^ 2 + (y - Math.ceil(y)) ^ 2 <= 1);
}
if (!(Math.ceil(x) % 2) && Math.floor(y) % 2) {
  return ((x - Math.ceil(x)) ^ 2 + (y - Math.floor(y)) ^ 2 <= 1);
}
return false;

Math.ceil - round up, Math.floor - down, ^2 - squared

S
Sergey Sokolov, 2021-09-28
@sergiks

Here, as it were, filled circles, with step 2:
with centers at ( 2 * i, 1 + 2 * j )where iand jintegers.
Odd quarters were cut off from the circles.
I do not write in C ++, an example in JS:

function isInArea(x, y) {
  centerX = 2 * Math.round(x/2);
  centerY = 1 + 2 * Math.round((y - 1)/2);
  if (! ((x >= centerX) ^ (y >= centerY))) { // НЕ (XOR)
    return false;  // не та четверть
  }
  // проверить расстояние
  return 1 >= (x - centerX) * (x - centerX) + (y - centerY) * (y - centerY);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question