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.
Page Index Toggle Pages: 1
3D Trig (Read 608 times)
3D Trig
Mar 23rd, 2009, 6:40pm
 
I am adapting a simple, 2D, boids-like flocking simulation to 3D, and I have been trying to figure out how to recreate the 'tails' of the boids. The tail is basically an array of spring objects, attached to the next one in the chain. To draw the tail I calculated two points to both sides of the location of the spring object, and drew simple quads.
For the 3D version, I am trying to define a ring of points around the spring object, and render each triangle based on the points of its ring, and the rings of the adjacent spring objects on the chain. I have been able to calculate the points, but only oriented in the direction of the screen.

float interval_ang = radians(360 / render_detail);
for (int i = 0; i < render_detail; i ++) {      
     float x = (sin(interval_ang*i)*radius);
     float y = (cos(interval_ang*i)*radius);
     float z = 0;
     ring[i] = new PVector(x,y,z); // ring locations are stored based on spring object location
   }

My trig skills extend only to basic 2D. How do I incorporate z, and rotate the entire array based on the heading of the spring object?


Re: 3D Trig
Reply #1 - Mar 24th, 2009, 4:56pm
 
ok you say you have the tail in 2d, so you should start by saving the 3d tail path points.
now you have the "head" and the segment points of your tail

now:

for each segment point i:
Vector3 T = tail[i+1] - tail[i];
Vector3 N = tail[i+1] + tail[i];
Vector3 B = Vector3.cross( T, N );  // get B by crossproduct
N = Vector3.cross( T, B );  //recompute N
T.normalize();
B.normalize();
N.normalize();

now you have the coordinate system of each segment of your tail. from here you can build the mesh orientated to the axis you want -i believe you would go for T. its the axis along your tail-

the simplest thing would be to just draw a plane aligned to T, and with some width along the B. N would become your plane normal

that would give you good results.
Re: 3D Trig
Reply #2 - Mar 25th, 2009, 3:44pm
 
Thanks, I now understand how to get the coordinate system. How would I  generate the points for a circle perpendicular to the main direction vector?

I would then use those points as 'ribs' along the length of the tail.

That would mean the tail is visualized as a tube, not as a series of planes.
Re: 3D Trig
Reply #3 - Mar 26th, 2009, 12:09pm
 
you will use the two axis N and B to create vertices around the direction vector T. i'll just put here the code i used to create the fashion ribbon effect. it should help you out. it can't compile as it is. you will have to figure out how to fit your own implementation.

source code at: www.pixelnerve.com/downloads/processing/RibbonCylinder.pde

for the mesh generation and render search for the method 'renderTailCylinder()'
Page Index Toggle Pages: 1