Calculating rectangle corners location in rotating around a pivot line

312 Views Asked by At

I'm trying to transform shapes in an Android app by rotating them around a pivot line (using View.setRotationY). As you see in the below images, I rotate the shape around the green line which is parallel to the vertical axis and crossed the center point of the rect. Looking at its 2D drawing makes sense that the left edge comes forward and the right edge goes backward. Now I want to formulate it. I mean the length of the edges based on rotation angle as well as their movement.

Any suggestions are really appreciated.

Rotation Angle: 0°

enter image description here

Rotation Angle: 15°

enter image description here

Rotation Angle: 30°

enter image description here

Rotation Angle: 45°

enter image description here

Rotation Angle: 60°

enter image description here

Rotation Angle: 75°

enter image description here

Rotation Angle: 90°

enter image description here

2

There are 2 best solutions below

10
On BEST ANSWER

Assuming a square of sides 2 units, the spatial coordinates of the four vertices are

$$(x,y,z)=(r\cos\theta,s,r\sin\theta)$$ where the $r$ and $s$ are $\pm1$ independently, and $\theta$ is the rotation angle around the vertical axis ($y$).

Now their perspective projection, assuming the viewpoint at $f$ units in the direction of the $z$ axis is

$$(X,Y)=\left(\frac{fx}{z+f},\frac{fy}{z+f}\right)=\left(\frac{fr\cos\theta}{r\sin\theta+f},\frac{fs}{r\sin\theta+f}\right).$$

enter image description here

0
On

Assume the edge length at zero angle is $a$ and the edge length at 90-degree angle is $b$, you may formulate the edge length as function of the rotation angle $\theta$ as,

$$L(\theta) = b\sin\theta + a(1-\sin\theta)$$

Such a relationship is based on the assumption that the edge length varies linearly with respect to the front-back distance.