Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → Geometry question
Geometry question
2004-05-29, 5:44 AM #1
Alright, I'm making a 2D tank game for my final project in programming in a Java applet. The tanks each have a polygon object which represents their bounding box, and I can check when the bounding boxes collide. So, I need to find the 4 vertices of a rectangle when I know it's centre, width, height, and angle of rotation. The angle is the same as the cartesian plane, 0 is facing right. I can get it to work if it's a square, but my algorithm falls apart if I apply it to a rectangle. Does anybody know/can easily develop a formula for finding the vertices? Thanks.

------------------
BV's rendition of Titanic: Let's have sex. I won't let go. I don't need this stone.
The End.
~ Wolfy
That painting was a gift, Todd. I'm taking it with me.
2004-05-29, 6:21 AM #2
I'm only 15, so please excuse me if my answer is way off. I just figured I'd take a stab at it. If it's a rectangle, than all four angles are congruent right angles. hence, if you split the rectangle from the top right hand vertex down to the bottom lfet hand vertes, you'll have two congruent right triangles. Like so, I think.

[http://img17.photobucket.com/albums/v52/RossD/geometrica.gif]

Sorry about the bad pic. Anyway, couldn't you then use the pythagorean theorem (since you said you knew width and height) to find the diagonal length. Then, since you know the center of the rectangle, maybe you could divided the result you got by two and you'd then have the distance from the center to each vertex. You could then probably work out there origins of each vertex on a 2D coordinate plain.

I hope I didn't make too much of an idiot out of myself, I only just took Geometry this year. I hope that helps a bit. [http://forums.massassi.net/html/redface.gif]

[EDIT: I made a slightly better pic.]

[2nd Edit: actually, rereading what you said, what you're asking for sounds incredibly simple. I must be missing something totally here. Could you perhaps rephrase the question, maybe with a diagram?]

------------------
~ Vader's Corner ~

[This message has been edited by Daft_Vader (edited May 29, 2004).]

[This message has been edited by Daft_Vader (edited May 29, 2004).]
My JK Level Design | 2005 JK Hub Level Pack (Plexus) | Massassi Levels
2004-05-29, 12:34 PM #3
V1 = <(w/2*cosθ - h/2*sinθ)+center.x , (w/2*sinθ + h/2*cosθ)+center.y>

V2 = <(-w/2*cosθ - h/2*sinθ)+center.x , (-w/2*sinθ + h/2*cosθ)+center.y>

V3 = <(w/2*cosθ - -h/2*sinθ)+center.x , (w/2*sinθ + -h/2*cosθ)+center.y>

V4 = <(-w/2*cosθ - -h/2*sinθ)+center.x , (-w/2*sinθ + -h/2*cosθ)+center.y>

I think.

I cheated, though.

[This message has been edited by Ictus (edited May 29, 2004).]
2004-05-29, 1:18 PM #4
[http://img.villagephotos.com/p/2004-5/735211/vector1.JPG]

Assuming I didn't make any horrendous mistakes, this should work if you use some sort of vector system in your game. You'll have to work out the rest for yourself, it's one in the evening now and I really should go to bed. It was great fun, though [http://forums.massassi.net/html/smile.gif]

[Edit: Let me know if it works and if it doesn't. Getting the coordinates of the other vertexes probably just means putting some minuses here and there in the formula [http://forums.massassi.net/html/biggrin.gif]]

------------------
No signature for you.


[This message has been edited by Gandalv the Gray (edited May 29, 2004).]
No signature for you.
2004-05-30, 6:20 AM #5
What they said

------------------
Wiggle your big toe.
Wiggle your big toe.
Wiggle your big toe.
Wiggle your big toe.
Stuff
2004-05-30, 2:49 PM #6
Awesome, I'll try it out tomorrow at school.

------------------
BV's rendition of Titanic: Let's have sex. I won't let go. I don't need this stone.
The End.
~ Wolfy
That painting was a gift, Todd. I'm taking it with me.
2004-05-30, 4:20 PM #7
Wait... won't Gandalv's way make every x-coordinate 0?

------------------
BV's rendition of Titanic: Let's have sex. I won't let go. I don't need this stone.
The End.
~ Wolfy
That painting was a gift, Todd. I'm taking it with me.
2004-05-30, 10:56 PM #8
Erm...I had hoped not...how? It doesn't when I put in some example numbers...

------------------
No signature for you.
No signature for you.
2004-05-31, 10:30 AM #9
Haha, I misread your decimal places as commas. Thanks for the help!

------------------
BV's rendition of Titanic: Let's have sex. I won't let go. I don't need this stone.
The End.
~ Wolfy
That painting was a gift, Todd. I'm taking it with me.
2004-05-31, 11:52 AM #10
I used to know this stuff!
/me cries

------------------
Truth is in the eye of the beholder.
Forum Rules
Little angel go away
Come again some other day
Devil has my ear today
I'll never hear a word you say

↑ Up to the top!