Rotate line based on updated mouse position

So far I have something like this:

public Vector2 RotateLineAboutIntersectionPoint(Vector2 intersectionPoint, Line line, Vector2 mousePosition)
       {
           double angle = Math.Atan2(mousePosition.y - intersectionPoint.y, mousePosition.x - intersectionPoint.x);
           double newPointOne = (line.point1.x - intersectionPoint.x) * Math.Cos(angle) - (line.point1.y - intersectionPoint.y) * Math.Sin(angle) + intersectionPoint.x;
           double newPointTwo = (line.point1.x - intersectionPoint.x) * Math.Sin(angle) + (line.point1.y - intersectionPoint.y) * Math.Cos(angle) + intersectionPoint.y;
       
           return new Vector2((float)newPointOne,(float)newPointTwo);
       }

I noticed that when I use this method, my mouse position never changes, so the line never rotates. I noticed it might have to do with needing to update the current mouse position every time the mouse moves and not just passing in the current mouse position. How do I update the mouse position when I can trying to drag/rotate the line?

Are you retrieving Input.mousePosition every update? Like:

void Update(){
Vector2 mousePosition = Input.mousePosition;
RotateLineAboutINtersectionPoint(intersectionPoint, line, mousePosition);
}

Alternatively, using Input.mousePosition directly in your function:

 public Vector2 RotateLineAboutIntersectionPoint(Vector2 intersectionPoint, Line line)
{
Vector2 mousePosition = Input.mousePosition;

double angle = Math.Atan2(mousePosition.y - intersectionPoint.y, mousePosition.x - intersectionPoint.x);
double newPointOne = (line.point1.x - intersectionPoint.x) * Math.Cos(angle) - (line.point1.y - intersectionPoint.y) * Math.Sin(angle) + intersectionPoint.x;
double newPointTwo = (line.point1.x - intersectionPoint.x) * Math.Sin(angle) + (line.point1.y - intersectionPoint.y) * Math.Cos(angle) + intersectionPoint.y;
return new Vector2((float)newPointOne,(float)newPointTwo);
}

Apologies for the layout of the code, I can’t seem to add tabs :confused: