Convert from one segment to another in 2D-coordinate system

84 Views Asked by At

Given a 2D-coordinate system where we only look at the area between 0-1 on both, x and y axis. How can I divide that system into n segments and mirror a point at p(0.5,0.5), so that all points are finally inside of the same segment?

I created a small drawing which I've attached here. In the drawing I used n=4 (but I want to come up with a solution where I can dynamically change the number of segments) to divide the coordinate system into 4 segments and marked the segment which should contain all points after mirroring (2nd). In 3rd I illustrated the mirroring I want to get. Points which are already in that marked segment should stay there. A point which is inside of another segment should be mirrored so that it finally belongs to the marked segment.

Image to illustrate the wished mirroring

I'm really sorry if the question is not precise enough and hope you understand what I want to achieve. I'm not a mathematician but a programmer and just need that kind of math for a mandala drawing app I'm currently working on.

Edit: Solved the problem by putting some code together and experimented a bit. When uv is our point, I calculate the new point uv' as followed:

Vector2 sc = uv - (Vector2.one*0.5f);
            float phi = Mathf.Atan2(sc.y, sc.x);
            float r = Mathf.Sqrt(Vector2.Dot(sc, sc));

            int segments = 8; 
            float _Divisor = Mathf.PI * 2 / (segments-2);
            phi = phi - _Divisor * Mathf.Floor(phi / _Divisor);
            phi = Mathf.Min(phi, _Divisor - phi);

            // Convert back to the texture coordinate.
            Vector2 uvNew = new Vector2(Mathf.Cos(phi), Mathf.Sin(phi)) * r + (Vector2.one*0.5f);

            // Reflection at the border of the screen.
            uv = Vector2.Max(Vector2.Min(uvNew, (Vector2.one*2f) - uvNew), -uvNew);
1

There are 1 best solutions below

1
On

This is not an answer, but it's longer than a comment. I have a series of questions that you might want to think about:

  1. How would you define your division into 3 or 5 segments?
  2. Why did you choose that particular shaded area, and not any of the other ones?
  3. A similar division in 4 can be done using vertical and horizontal lines, like a $+$ symbol. Is there a reason why you choose $\times$?
  4. Just mirror point at $(0.5,0.5)$ is not enough to bring all points into the shaded area. Say one of your points is at $(0.8,0.9)$. In your figure you move it to $(0.9,0.8)$. But the symmetry of the mirror point would instead move it to $(0.2,0.1)$. If you repeat the same symmetry operation twice, you will get back to the original point. From the picture, it looks like you used additional symmetry operations, some mirror planes (lines) along the diagonals. Alternatively one can use rotations by multiples of $90^\circ$. But then your point would move from $(0.8,0.9)$ to $(0.9,0.2)$. Would that be OK?