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.
IndexSuggestions & BugsWebsite,  Documentation,  Book Bugs › How do I edit Processing Hacks
Page Index Toggle Pages: 1
How do I edit Processing Hacks (Read 1735 times)
How do I edit Processing Hacks
Dec 31st, 2008, 1:52pm
 
I found this page today:

http://processing.org/hacks/hacks:collision_detection

Seeing as I work in games development, I know a more efficient method of testing circle collision than detailed on the page. But I can't edit the page for some reason.

I mean to change:
Code:

void circle_collision(x_1, y_1, radius_1, x_2, y_2, radius_2)
{
return dist(x_1, y_1, x_2, y_2) < radius_1+radius_2;
}


to

Code:

void circle_collision(x_1, y_1, radius_1, x_2, y_2, radius_2)
{
return (x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (x_2 - x_1) < (radius_1 + radius_2) * (radius_1 + radius_2);
}


Function calls are expensive. The squareroot required to measure distance is also expensive. By inlining the whole operation and avoiding using a squareroot, you get the most efficient circle collision test.

I'd put this on the hack page, but I can't figure out how.
Re: How do I edit Processing Hacks
Reply #1 - Dec 31st, 2008, 4:00pm
 
You have a Login link in the page. You should be able to log in using your forum login.
I suggest you keep both versions, explaining why you think your method is better, as you did here. Giving some benchmark values to backup your suggestion.
Re: How do I edit Processing Hacks
Reply #2 - Dec 31st, 2008, 4:14pm
 
hi aaron!

the page was acc. locked, fixed now. thanks for letting us know.

you can edit the content by clicking the edit button to the upper right of each block.

btw. i think your website has been hacked .. it redirects me to some virus scanner page ..

F
Re: How do I edit Processing Hacks
Reply #3 - Jan 3rd, 2009, 1:45am
 
Something to with Blogger that is.

I may have to try and convert the lot to wordpress or something.
Re: How do I edit Processing Hacks
Reply #4 - Jan 3rd, 2009, 2:58pm
 
Code:

int timer, i;
void setup(){
timer = millis();
for(i = 0; i < 10000000; i++){
circle_collision(1.0,2.0,3.0,4.0,5.0,6.0);
}
println(millis()-timer);
timer = millis();
for(i = 0; i < 10000000; i++){
circle_collision2(1.0,2.0,3.0,4.0,5.0,6.0);
}
println(millis()-timer);
}
Boolean circle_collision(float x_1, float y_1, float radius_1, float x_2, float y_2, float radius_2)
{
return dist(x_1, y_1, x_2, y_2) < radius_1+radius_2;
}
Boolean circle_collision2(float x_1, float y_1, float radius_1, float x_2, float y_2, float radius_2)
{
return (x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (x_2 - x_1) < (radius_1 + radius_2) * (radius_1 + radius_2);
}

Runs twice as fast.

Also the methods on the page are listed as void, returning no value despite having return values, and there were no datatype idents.
Re: How do I edit Processing Hacks
Reply #5 - Jan 3rd, 2009, 3:31pm
 
super, thanks!
F
Re: How do I edit Processing Hacks
Reply #6 - Jan 3rd, 2009, 5:57pm
 
there is a typo in the return statement, should be:
Code:

Boolean circle_collision2(float x_1, float y_1, float radius_1, float x_2, float y_2, float radius_2)
{
return (x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) * (y_2 - y_1) < (radius_1 + radius_2) * (radius_1 + radius_2);
}

//  fB
Re: How do I edit Processing Hacks
Reply #7 - Jan 4th, 2009, 8:03pm
 
cheers - fixed
Page Index Toggle Pages: 1