|
-
Sep 26th, 2012, 11:29 AM
#1
[RESOLVED] calculating vertices of a square
assuming i have a square:

+ 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?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 26th, 2012, 11:54 AM
#2
Re: calculating vertices of a square
IF
A = X1, Y1
C = X2, Y2
THEN
B = X2, Y1
D = X1, Y2
-tg
-
Sep 26th, 2012, 11:59 AM
#3
Re: calculating vertices of a square
i forgot to mention, the square will be rotated
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 26th, 2012, 02:09 PM
#4
Re: calculating vertices of a square
Given A and C (as PointF) then
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
I hope.... I did it "by eye". Let me know.
-
Sep 26th, 2012, 10:19 PM
#5
Re: calculating vertices of a square
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.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Sep 27th, 2012, 11:30 AM
#6
Re: calculating vertices of a square
 Originally Posted by Inferrd
Given A and C (as PointF) then
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
I hope.... I did it "by eye".  Let me know.
 Originally Posted by jemidiah
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.
thanks for the help. the formulas proved to be the simplest solution...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|