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 & HelpPrograms › Curve-Ellipse Intersection
Page Index Toggle Pages: 1
Curve-Ellipse Intersection (Read 925 times)
Curve-Ellipse Intersection
Nov 11th, 2009, 1:10pm
 
Hi, I´m doing a small game and need to check a collision between a curve, drawing with the mouse like the processing example, and a moving ellipse.

Basically, I store the mouse coordinates in a arraylist and then draw lines between the points stored. I know the equations to check line-circle intersection mathworld.wolfram.com/Circle-LineIntersection.html but the computation is very intense, with many square roots,  and I need to test the intersection with a lot of lines every frame.

I was thinking of checking the colors of the pixeis (the ellipse and th have different collors in my game) but I don´t know if we can access the video buffer in processing. Does anyone know any simpler method?
Re: Curve-Ellipse Intersection
Reply #1 - Nov 11th, 2009, 6:33pm
 
It is possible to directly access the color of the pixel under the mouse.
For example:

void draw(){
 background(0);
 noStroke();
 fill(color(255,0,0));
 rect(10,10,20,20);
 fill(color(0,0,255));
 rect(10,70,20,20);
 fill(color(0,255,0));
 rect(70,10,20,20);
 fill(color(random(255),random(255),random(255)));
 rect(70,70,20,20);
 loadPixels();
 fill(pixels[(width*mouseY)+mouseX]);
 rect(40,40,20,20);
}

Hope this helps!
Re: Curve-Ellipse Intersection
Reply #2 - Nov 12th, 2009, 9:33am
 
Thanks for your answer TF. I forgot this function loadPixels. If I can get the pixels around the mouse I can also get the pixels around the center of the ellipse.
Re: Curve-Ellipse Intersection
Reply #3 - Nov 12th, 2009, 11:07am
 
or just  fill(get(mouseX,mouseY));
Page Index Toggle Pages: 1