I have been working on an application over the past few weeks that is associated with some trigonometry, and I'm currently stuck. As shown in the diagram below, I have a round element (green circle at position No. 1) that I know at the center point (let me call it X1, Y1). The circle has another point (orange circle), which is a bit off-center - halfway between the other two marks (blue circles). These marks can be moved. The coordinates of the orange point are calculated (let it be called X2, Y2) and the angle of the blue line (call it the angle) relative to the horizontal of the circle is calculated.

I can calculate the difference between the center of the circle and the point:
deltaX = X2-X1
deltaY = Y2-Y1
I need to move and rotate the green circle (either CW or CCW - whichever is smaller) from its initial location (position 1) to position 2. This means that the angle can be negative or positive. The blue line should be vertical, and the orange dot should be in the center of position 2 (red square). I know the coordinates for the center of position 2 (let me call this point X3, Y3). Position number 1 and position number 2 are exactly 90 degrees apart.
I thought I could use some trigger formulas that calculate the rotation of a point, as such:
offsetX = deltaX * cos (90-Angle) - deltaY * sin (90-Angle)
offsetY = deltaX * sin (90-Angle) + deltaY * cos (90-Angle)
I was hoping that these offsets would be what I needed to set the circle to a new center when it moves / rotates to position 2.
X3 = X3 + offsetX
Y3 = Y3 + Offset Y
However, when I try to use this math, it does not put the orange circle mark in the center of the square. Not sure if my equations and calculations are correct depending on the angle of rotation (positive or negative, CW or CCW) or if I use the angle correctly (where I subtract the known angle from 90 degrees). How to calculate the end point / position? Any help and examples would be greatly appreciated!
Thanks so much for your time!
source share