We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Collision shape detection geomerative
Page Index Toggle Pages: 1
Collision shape detection geomerative (Read 756 times)
Collision shape detection geomerative
Feb 14th, 2009, 6:46pm
 
Hi folks,
once again a question about geomerative.
I am playing around with "contain" of geomerative. I found the tutorial detecting collision by a point to a svg shape.

What I need is to detect a collision of two svg shapes.
Does anybody has an idea what I have to change in the script?

the pde with the svgs are here:
www.sternmotor.de/svg.zip

import processing.xml.*;
import processing.opengl.*;
import geomerative.*;

RShape sh01;
RShape sh02;
boolean ignoringStyles = false;

void setup(){
 size(600, 600);
 smooth();
 g.smooth = true;

 // VERY IMPORTANT: Allways initialize the library before using it
 RG.init(this);
 RG.ignoreStyles(ignoringStyles);

 RG.setPolygonizer(RG.ADAPTATIVE);
 sh01 = RG.loadShape("txt_01.svg");
 sh02 = RG.loadShape("txt_02.svg");
 sh01.centerIn(g, 100, 1, 1);
 sh02.centerIn(g, 100, 1, 1);
 noLoop();
}

void draw(){
 background(255);
 stroke(0);
 noFill();
 sh01.translate(random(600),random(600));
 sh02.translate(random(600),random(600));
 sh01.draw();
 sh02.draw();
 /// Here is something wrong - but what???
 RShape p = new RShape(sh02.children[0]);
 if(sh01.children[0].contains(p)){
   /////////////////
   println("Hit");
 }
}
Re: Collision shape detection geomerative
Reply #1 - Feb 14th, 2009, 9:04pm
 
Hi,

Well there is no "real" collision detection in Geomerative.  Maybe the closest, however a bit inefficient would be to perform an intersection between two shapes and ask for the area.

Otherwise I have implemented a few methods that might be close enough to collision (contains(RShape) and intersects(RShape)).  You can find them in the new Geomerative rev 20:

http://www.ricardmarxer.com/geomerative/

Your sketch would then become:

http://www.ricardmarxer.com/processing/test3-rev.zip

If you need more speed, I have also added a few methods that act only on the Handles or even on the Bounding Box of the shape passed.

Good luck,
ricard
Re: Collision shape detection geomerative
Reply #2 - Feb 14th, 2009, 9:38pm
 
Works really perfect!
Thank you so much for your help - that saved me a lot of work!
Page Index Toggle Pages: 1