assuming i have a square:
Attachment 91803
+ i know the coordinates of point A + point C, or the coordinates of point B + point D...
how can i find the coordinates of the other 2 points?
Printable View
assuming i have a square:
Attachment 91803
+ i know the coordinates of point A + point C, or the coordinates of point B + point D...
how can i find the coordinates of the other 2 points?
IF
A = X1, Y1
C = X2, Y2
THEN
B = X2, Y1
D = X1, Y2
-tg
i forgot to mention, the square will be rotated
Given A and C (as PointF) then
I hope.... I did it "by eye". :p Let me know.Code:Dim B, D As New PointF
B.X = ((C.X + A.X) + (A.Y - C.Y)) / 2
B.Y = ((A.Y + C.Y) + (C.X - A.X)) / 2
D.X = ((C.X + A.X) - (A.Y - C.Y)) / 2
D.Y = ((A.Y + C.Y) - (C.X - A.X)) / 2
Given A and C, the center of the square is M = (A+C)/2. Suppose P is a vector perpendicular to the vector from A to C of the same length. Then B is M + P/2 and D is M - P/2. In 2D, it happens that given a vector (x, y), the vector (-y, x) is perpendicular to (x, y). Since the vector from A to C is C-A = (C.x - A.x, C.y - A.y), P is just (A.y - C.y, C.x - A.x). In all...
B.x = (A.x + C.x)/2 + (A.y - C.y)/2
B.y = (A.y + C.y)/2 + (C.x - A.x)/2
D.x = (A.x + C.x)/2 - (A.y - C.y)/2
D.y = (A.y + C.y)/2 - (C.x - A.x)/2
These formulas agree with Inferrd's, so they should be what you were after.