Geeks With Blogs
George Clingerman       XNADevelopment.com

rotatedrectangle There's a new XNA sample I've posted on XNADevelopment.com that demonstrates a method of detecting collisions between 2D rotated rectangles. I'm hoping to someday build a tutorial around this (maybe if I get enough requests for one!) but for now I've just made the source code available. I commented the code fairly thoroughly and made some attempt to write the code as readable as possible. It may be with those efforts that the sample will work well enough for most people without an accompanying tutorial.

I hope it's useful! As always, I welcome any feedback anybody might have and I hope this is useful to the XNA community.

Posted on Saturday, January 9, 2010 10:00 AM | Back to top


Comments on this post: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Id love this to be done thoroughly!
a tutorial would be perfect. Is it physics too though?
Left by Martin Pugh on Jan 16, 2010 2:04 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very good tutorial because so far everything thing I've seen on the subject has made it seam like its really hard to do but you make it simple. I'm just having one small problem, My sprites won't show up in the game in less i change your draw code from new rectangle(blahhh) to null. Any help on this? Also if i only have one rotating sprite do all my sprites that can collide
have to use this method?

Thankz a lot...


Left by johhny waffle on Jan 18, 2010 10:45 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
This is a great tutorial!!!
Left by BlazBlueAdmin on Jan 21, 2010 11:09 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
this wonderful event.
Left by diyet on Apr 12, 2010 10:22 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
A tutorial would be very usefull.
Thanks for this method !
Left by pronostics on May 05, 2010 5:02 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
how do i change it to make it so that i can rotate at any given origin?
Left by tom nui on Jun 10, 2010 2:31 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thankyou. :)
Left by Lyttlefreak on Jun 27, 2010 1:43 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
@tom nui, re:origin
I managed to incorporate a given origin by creating a new constructor with a third vector 2 parameter that was used to set the Origin field. I then changed any negative Origin references to be subtracted from the width/height of the collissionRectangle. i.e
"-Origin.X" became "-(CollisionRectangle.Width - Origin.X)" and "-Origin.Y" became "-(CollisionRectangle.Height- Origin.Y)". Probably not the prettiest solution but it did SEEM to work for me (which suprised me a little as most of the sample code went over my head).

Thanks again for the sample code, I now have lasers (that work). :)
Left by Lyttlefreak(newb) on Jun 27, 2010 10:51 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very usefull tuto, it will help me, thanks a lot.
Left by canalwin on Aug 06, 2010 2:26 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
This is a great ressource for everyone, thanks a lot.
Left by parionsweb on Aug 06, 2010 2:30 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
nice article, i hope you will build the tutorial to learn a little more.
Left by canalwin on Sep 17, 2010 9:35 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...


There is currently some useful information that regarding to health problem around this subject on the net and some are most definitely better than others. You have caught the detail here just right which makes for a refreshing change – thanks.
Left by Internet Marketing on Jan 17, 2011 4:02 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Nice post collision detection i have always needed help on, thanks!
Left by gift ideas on Mar 29, 2011 1:37 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very nice tutorial can give functions to indiciduals.
Left by Manuel Oquinn on May 01, 2011 9:31 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very good tutorial because the post provided some thoughts.
Left by zeka oyunları on May 05, 2011 2:20 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Ultrasound Technician is responsible and capable of managing ultrasound equipment and any other related apparatus.
Left by Website ultrasound Technician on May 06, 2011 10:31 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Great blog, nice work!
Left by erotic stories on May 06, 2011 2:34 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
indeed new sample on 2D is perfect in collisions .As these collisions have different effects
Left by it services companies on May 16, 2011 3:05 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
here I found it. I am doing a project and this information is very useful me. If you are interested, but this is my duty to inform you that healthy is very important. So let take time to take care of your body. Click here to get free information on Healthy weight loss.
Left by ipod cases on May 30, 2011 3:34 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but this articles is best.

Facebook Landing Page
Left by maimi on Jul 10, 2011 1:32 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
This is a invaluable website and i also are finding reliable information below and that i actually value the attempts from the writer with this composition for revealing nice tips. Many thanks!
Left by information on car insurance on Jul 27, 2011 12:56 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thanks for the info! interesting post
Left by lina on Sep 08, 2011 10:06 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
keep it up. Thanks for the post!
Left by fashionable swimsuits on Sep 08, 2011 10:08 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...


That is this kind of exceptional resource that you simply are supplying so you give it absent totally free of cost. I value viewing world wide web websites that understand the appeal of presenting a prime resource for no value. I truly cherished studying your submit. Thanks!

Left by Ayurveda on Sep 19, 2011 7:54 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Good tutorial, thanks ! springkussen
Left by Bradon Hops on Sep 29, 2011 2:41 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
really interesting.I really enjoyed reading it so that is why I will check your posts every day.Thank you so much for your effort.Logomatten

Left by Logomatten on Oct 10, 2011 2:24 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
I read your post and I found it amazing .Your thought process is wonderful. The way you express yourself is awesome. Hey, your blog is great. I will bookmark it and I plan to visit regularly.
Left by Nigerians on Oct 13, 2011 5:23 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Hi, im really interested in how your app work. In XDA we are talking about overclocking of MSM7201a , but i have no idea about how your program can be ported to android. Do you see it possible?

Thank you!
Left by dragon ball z games on Oct 27, 2011 10:51 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
really interesting.I really enjoyed reading it so that is why I will check your posts every day.Thank you so much for your effort
Left by Berufstest Berufswahltest on Nov 02, 2011 8:23 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
looking forward to the tutorial! 5554
Left by netixpress on Nov 12, 2011 12:50 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Nice post collision detection i have always needed help on, thanks! Tips To Get Your Ex Back As Soon As Possible
Left by What To Say To Get Your Ex back on Nov 19, 2011 12:29 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
haha, Thanks for the spoof! It’s funny because I feel like so many people don’t even know how bad a no follow tag can be. I feel like all it does is hurt websites as a whole.
Left by yaz recall on Nov 21, 2011 5:56 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Great and very interesting post. Thanks.
Left by Chinese Dresses For Children on Nov 30, 2011 6:08 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
I read your post and I found it amazing .Your thought process is wonderful. The way you express yourself is awesome. Hey, your blog is great. I will bookmark it and I plan to visit regularly for my Detektei Berlin
Left by Detektei Berlin on Dec 10, 2011 12:53 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
This is my first time i visit here. I found so many interesting stuff in your site especially its discussion. From the tons of response on your articles, I think I am not the only one having all the enjoyment here. Keep up the good work. Thanks for sharing…
Left by lexapro law firm on Dec 14, 2011 1:17 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
It`s awsome!! Thanks alot! It`s just like FUS RO DAH ))
Left by CkEsc on Dec 20, 2011 5:55 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Our stretch limousine represents class, elegance and luxury. Whether you’re getting married, having a night out with the girls or any occasion. Our Stretch limousine is your best choice for Limo hire Melbourne . Our new car introductory offer is a free bottle of champagne with every booking plus you’ll get a fantastic hire rate. The longer you hire the cheaper it gets per hour.
Left by Limo on Dec 30, 2011 4:27 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Great and very excellent post. Thanks.
Left by mode für mollige on Jan 23, 2012 4:12 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Great technique! Having some trouble getting it working, though. Any chance of a tutorial? Thanks
Left by Meneliki on Jan 24, 2012 7:53 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
A very nice post, thank you for this article as I learn something interesting
Logitech Wireless Mouse
Left by Best Wireless Mouse on Jan 25, 2012 2:14 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thanks Buddy for the post and allowing user comments on your post. Its great sign for the new visitors. Well done and keep up the good work. Regards top websites
Left by Best All In One Computer on Feb 01, 2012 11:42 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Great job on this.
Left by damkläder stora storlekar online on Feb 03, 2012 2:48 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
I would say that this is the best site that I have never seen before. It is really informative to the people as it shows lot of hard work and research by the staff at this website. There is no other website that has so much information this site has. Danish Poker History
Left by Danish Poker News on Feb 04, 2012 6:08 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thanks , I have recently been looking for info approximately this subject for a long time and yours is the greatest I have found out till now. But, what in regards to the bottom line? Are you sure concerning the supply?
Left by plus size dresses clothing uk on Feb 20, 2012 4:30 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
This post can make you lively. It's my pleasure that i found this post because I've always seeking all information.I want but through this post I've got everything. This is so good one of your reference.
Left by mode für mollige on Feb 27, 2012 6:16 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thanks for letting us know about this and I hope to read more from you. Keep the posts coming
Left by beddenzaak winkel woerden alphen on Mar 31, 2012 7:28 AM

# little league baseball umpire training
Requesting Gravatar...
Thank you for sharing such great information with us. I really appreciate everything that you've done here and am glad to know that you really care about the world that we live in
Left by to job on May 16, 2012 3:13 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...

Cool! That was a great tournament. I love the show. I just want to say congratulations to the winner.
This is a job well done! Keep it up!
Left by right here on May 29, 2012 2:02 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Thanks for taking this opportunity to discuss this, I feel strongly about it and I take pleasure in learning about this topic.
If possible, as you gain information, please add to this blog with new information. I have found it extremely useful.
Left by right here on May 29, 2012 2:02 AM

# fashion online
Requesting Gravatar...
Thanks for sharing this useful information! Hope that you will continue with
Left by Sunny on Jun 30, 2012 1:02 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
That is awesome. Thanks for sharing this useful information, I'm going to check that source link. Keep up the goodwork.
Left by edward on Jul 25, 2012 4:38 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
The code seems to no longer exist... by which I mean, I can't open it properly, it doesn't load the content.
Left by Halleflux on Aug 10, 2012 1:50 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Never mind, I figured it out.
Left by Halleflux on Aug 10, 2012 1:55 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very useful post. I'm looking for this 2d rotation. Thanks
Left by Ashlar Pattern on Sep 20, 2012 4:51 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Very well created and written article is posted here. Nice to read this.
Left by Local SEO on Dec 06, 2012 5:01 AM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
A simple but very useful information about 2D rotation. Thanks for the share.
Left by Miami Beach on Jan 24, 2013 2:50 PM

# re: XNADevelopment.com - New sample on 2D Rotated Rectangle Collisions
Requesting Gravatar...
Your code helped me a lot.

But I changed a few things, which might be interesting for you and others.
1. Changed your code in "GenerateScalar" to use Vector2.Dot(...)
2. To calculate the transformed corner points I use a Matrix. With it rotation AND scaling is very easy.

I did this to refactoring a bit and I always try to use existing functions of a framework because these are usually tested and optimised.

That's it - cheers for your good work!
Left by Code Flash on Jan 28, 2013 1:41 AM

Your comment:
 (will show your gravatar)


Copyright © George Clingerman | Powered by: GeeksWithBlogs.net