Transforms. How rotate point (Vector2) around another point (Vector2)?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By estebanmolca

I have a point1 (Vector2), I want this point to rotate around another point2 (Vector2) (On the same node without adding new nodes).
The rotated () function works but rotates point1 around the origin of the scene. How do I make the center of rotation of point1 be point2?
I try to do it with Transform 2D but I know how, and when I try to multiply Vector2 with Transform 2D it can’t. To visualize it I simply draw a small circle at the position of point 1 in _draw() function.

:bust_in_silhouette: Reply From: njamster

The rotated () function works but rotates point1 around the origin of the scene. How do I make the center of rotation of point1 be point2?

You just need to add point2 to the result. :wink: Also take a look at this answer.

Thanks, what is easy sometimes becomes difficult…My function to move the point and rotate it:

 func rotated_point(_center, _angle, _distance):
    	return _center + Vector2(sin(_angle),cos(_angle)) * _distance

estebanmolca | 2020-05-24 23:37

:bust_in_silhouette: Reply From: supper_raptor

Maybe this will help

var diff = point1 - point2
var rotated_vector = diff.rotated(angle) + point2

Thanks for the answer, the previous method worked for me but this is another way of doing the same …

estebanmolca | 2020-05-24 23:38