Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (768)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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 2116 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 28
Projects: 3
Exp: 5 years


https://github.com/wreed12345


« 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: 382
Projects: 11
Exp: 4 years


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


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

Here

Offline Phibedy

Senior Devvie


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: 28
Projects: 3
Exp: 5 years


https://github.com/wreed12345


« 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 Devvie


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

JGO Kernel


Medals: 518



« 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  
 
 

 
EgonOlsen (1339 views)
2018-06-10 19:43:48

EgonOlsen (1229 views)
2018-06-10 19:43:44

EgonOlsen (939 views)
2018-06-10 19:43:20

DesertCoockie (1380 views)
2018-05-13 18:23:11

nelsongames (1112 views)
2018-04-24 18:15:36

nelsongames (1374 views)
2018-04-24 18:14:32

ivj94 (2120 views)
2018-03-24 14:47:39

ivj94 (1269 views)
2018-03-24 14:46:31

ivj94 (2286 views)
2018-03-24 14:43:53

Solater (808 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!