Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Detecting Collision between a rectangle and a circle?  (Read 830 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Posted 2012-12-02 01:16:29 »

how would i detect the collision between a rectangle and a circle? both of these are images btw.

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2012-12-02 01:26:13 »

Here

Offline Phibedy

Senior Duke


Medals: 9



« Reply #2 - Posted 2012-12-02 14:44:10 »

[CODE]public static boolean cricleVsRect(PCircle c, PRectangle p){
         if(p.containsPoint(PVector.add(c.getLocation(), new PVector(0, c.getRadius())))
               || p.containsPoint(PVector.add(c.getLocation(), new PVector(0, -c.getRadius())))
               || p.containsPoint(PVector.add(c.getLocation(), new PVector(c.getRadius(),0)))
               || p.containsPoint(PVector.add(c.getLocation(), new PVector(-c.getRadius(),0)))){
            return true;
         }
         if(c.containsPoint(p.getLocation())
            || c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), 0)))
            || c.containsPoint(PVector.add(p.getLocation(), new PVector(0, p.getHeight())))
            || c.containsPoint(PVector.add(p.getLocation(), new PVector(p.getWidth(), p.getHeight())))
            )
            return true;   
         return false;   
      }
[/CODE]
"[rectangle].getLocation()" returns the upper left corner of the rectangle.
"[circle].getLocation()" returns the middle of the circle.

If it's possible to solve it faster, feel free to critizise Smiley
best regards
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wreed12345

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #3 - Posted 2012-12-02 15:35:03 »

i do not understand this at all...lol and i am getting a bunch of errors when trying to use this

Offline Agro
« Reply #4 - Posted 2012-12-02 16:16:18 »

wreed, you can just use AABB to do it. DrHalfway posted an article int he Articles section that explains the AABB method.

Offline Phibedy

Senior Duke


Medals: 9



« Reply #5 - Posted 2012-12-03 17:21:29 »

PVector and PRectangle are custom classes. You can't just copy the code, but if you have questions about it, feel free to ask.
Offline Roquen
« Reply #6 - Posted 2012-12-03 17:58:39 »

http://www.java-gaming.org/topics/vectors-what-s-the-point/24307/msg/225743/view.html#msg225743
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (67 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!