To rotate B
90 degrees around A
:
diff = B-A
B_new = A + array([-diff[1],diff[0]])
To be more general, you do this:
def rot_origin(p, ang):
return array([p[0]*cos(ang)-p[1]*sin(ang),p[0]*sin(ang)+p[1]*cos(ang)])
def rot_around(p, p0, ang):
return p0 + rot_origin(p-p0, ang)
Then, your case would be B_new = rot_around(A, B, pi/2)
, since 90
degrees is pi/2
radians.
Edit: Just to make it completely explicit for your example. To rotate by 90 degrees around point 1, you would get:
(x1,y1) (x1-(y2-y1),y1+(x2-x1))
To rotate around point 2, you would get:
(x2-(y1-y2),y2+(x1-x2)) (x2,y2)