FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Automated Systems
(Moderator: REAS)
   distance calculation in a confined 3D env.
« No topic | Next topic »

Pages: 1 
   Author  Topic: distance calculation in a confined 3D env.  (Read 2111 times)
Eilsoe

WWW Email
distance calculation in a confined 3D env.
« on: Mar 9th, 2005, 11:31pm »

alright, I've only been working with p5 for 3 days now, so I'm not all wizard-like, like many of you fine people here
 
I just got the hang of classes, arrays and the *cough* rotateXYZ functions *cough*
 
anyway, I utilized it into making a cubeshaped field in which to spawn a few hundred particles. each p follows a random path (defined at birth) and bounces of walls within the field.
a line is drawn between 2 p's if the distance between 'em is less than a third of the diameter of the field. (I dunno if there's an easy way to calc. distance in 3D... I just used a double pythagoras equation)...
 
also opacity of the created line is proportional to the distance.
 
mousemovement rotates the field, hold down the mousebutton to pause particle movement, release to play again.
 
 
www.avalon-rev.dk/p5/3D2/
 
 
« Last Edit: Mar 9th, 2005, 11:33pm by Eilsoe »  

Kirupaforum moderator...
JohnG

WWW
Re: distance calculation in a confined 3D env.
« Reply #1 on: Mar 15th, 2005, 4:03pm »

You cna probably significantly speed up the "distance check" part of your code.
 
In 2D the distance can be foudn with sqrt(x^2 + y^2), as you've done, and then you've added in the z^2 calc, however if you rememebr what "d1" is in your code, you're doing:
 
sqrt((sqrt(x^2+y^2))^2 + z^2)
i.e. you're calculating the square root, then squaring it again, so you can speed thi up b changing it to:
sqrt(x^2+y^2+z^2);
 
you can then speed this up even more, by not doin gthe suqare root at all, and comparing the square of the distance against the square of the "minimum distance" variable you have.
 
Pages: 1 

« No topic | Next topic »