Rotating two objects

36 Views Asked by At

I have two lines. Both created in this format: Line 1 $$line1 = \left\{ \begin{array}{c} startX, startY \\ endX, endY \end{array} \right\}$$ $$line2 = \left\{ \begin{array}{c} startX, startY \\ endX, endY \end{array} \right\}$$

For example: $$line1 = \left\{ \begin{array}{c} 0, 0 \\ 50, 50 \end{array} \right\}$$ $$line2 = \left\{ \begin{array}{c} 0, 0 \\ 75, 75 \end{array} \right\}$$

I want to rotate them, but rotate them so that line2 will be to able have its center of rotation at points endX,endY of line1.

ie:
enter image description here

Then:
enter image description here
And then:
enter image description here

Both lines have a matrix of modelview. I made up the following(STARTING): $$vecSize = \left\{ \begin{array}{c} line1.endX - line1.startX;line1.endY - line1.startY; \end{array} \right\} $$ $$matLine1 = matLine1 * mat4(translate(100, 100, 0))$$ $$matLine2 = matLine2 * mat4(translate(100, 100, 0)) * mat4(translate(vecSize.X, vecSize.Y, 0))$$

And I got the following: enter image description here
If I do this: $$matLine1 = matLine1 * mat4(rotate(90, vec2d(0, 0, 1))$$ $$matLine2 = matLine2 * mat4(translate(-vecSize.X, -vecSize.Y, 0))$$ $$matLine2 = matLine2 * mat4(rotate(90, vec2d(0, 0, 1))$$ $$matLine2 = matLine2 * mat4(translate(vecSize.X, vecSize.Y, 0))$$ Very good. I see this: enter image description here
If I do this(after STARTING): $$matLine2 = matLine2 * mat4(rotate(20, vec2d(0, 0, 1))$$ $$matLine1 = matLine1 * mat4(rotate(90, vec2d(0, 0, 1))$$ $$matLine2 = matLine2 * mat4(translate(-vecSize.X, -vecSize.Y, 0))$$ $$matLine2 = matLine1 * mat4(rotate(90, vec2d(0, 0, 1))$$ $$matLine2 = matLine2 * mat4(translate(vecSize.X, vecSize.Y, 0))$$ I see this: enter image description here
I want all rotation and translation for line2 to be relative to line1. Line2 should rotate about {Line1.endX, Line1.endY};