Assume I have a rectangle having 4 vertices (x1,y1), (x2,y2) (x3,y3) and (x4,y4)
. These vertices are in clockwise order.The rectangle is oriented like (x1,y1) is the top most left side corner and (x3,y3) is the bottom most Right Corner.
Now i want to rotate the rectangle around one of the edge i,e along the edge that includes (x2,y2) and (x3,y3).I want to achieve this effect in Shaders by rotating two Vertices (x1,y1) and (x4,y4).
My question is What is the formula for Rotating a point (x1,y1) with an angle Theta around a certain point.
I have searched the older forums and found some relevant information https://stackoverflow.com/a/3162657/1804924
My question is can i use the equation as it is.. because it is like rotation about Y-axis.
There's a series of articles that goes over the math for 2D rotations here
https://webglfundamentals.org/webgl/lessons/webgl-2d-rotation.html
It's starts simple and builds up to 2D matrix math which is the most common way to do this stuff
Once you have the matrices working you'd generate a matrix that translates the rectangle so that the point between X2,y2 and x3,y3 is at 0,0. Then generate a matrix that rotates. Then another to translate back. Multiply them all together and you'll get one matrix that does the entire thing.
Now use that matrix
Here's an example. It's rotating halfway between around the center of the right edge.
basically to rotate an object around the vector you need to translate(and rotate if needed) it in such way that this vector will appear in middle so your object will be positioned in vectors local coordinate system. then you apply rotation and after it put object back where it was. Here is good helper library.