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 › How to calculate these points. 3d space
Page Index Toggle Pages: 1
How to calculate these points. 3d space (Read 2265 times)
How to calculate these points. 3d space
Nov 4th, 2009, 2:41pm
 
I tried to figure out how to calculate some coordinates in 3d space but i I just realized my math is not the best so i am asking for some help here.

I am using traerphysics to create some tendrils in 3d space. that works fine. But now I dont want to draw just lines connecting the particles, i want to draw either a plane quadstrip or 3d volume arround these tendrils.
to do so i need to calculate some points...

i made this great drawing, showing what i got and what i need.
the green X are my particles,  i got these coordinates and allready draw the white line. but now i want to draw something like the blue quadstrip and therefore need the red X that i dont have. How can i calculate them not only in 2d but in 3d space.

I read about using, vector cross products, but i couldnt figure out how to do this. its similar to what he did in his posting : http://blog.arsthanea.com/2009/06/25/geon/

...

Thanks for your help!

Re: How to calculate these points. 3d space
Reply #1 - Nov 4th, 2009, 3:06pm
 
So, you have a ring of points around each X, tilted in 3D along the angle of the tendril at that point?

Easiest way that comes to mind for me is to avoid vectors entirely and track the angle at each point (one angle in 2d and two angles in 3d)...and use sin/cos to find a ring of points perpendicular to that angle.
Re: How to calculate these points. 3d space
Reply #2 - Nov 4th, 2009, 4:21pm
 
sounds good.
i am  having a hard time trying to figure that out. could you think of a good way? i converted these lines to vectors and calculatet the angle between them, but have the problem that i only get values between 0-180 and not 180-360. so its only working half of the circle. dont know if that makes sense anyway. so is that a good way at all? Any other ideas ?

is this stuff maybe available in some of the libraries, for example toxiclibs and I just dont know about it ?

this is what ive got so far,
Code:
void setup(){
 size(400,600,P3D);
}

void draw(){
 float x1 = 100;
 float y1 = 100;
 float x2 = 100;
 float y2 = 300;
 float x3 = mouseX;
 float y3 = mouseY;

 background(255);
 stroke(0);

 line(x1,y1,x2,y2);
 line(x2,y2,x3,y3);

 PVector v1 = new PVector(x2-x1,y2-y1);
 PVector v2 = new PVector(x2-x3,y2-y3);

 float a = PVector.angleBetween(v1, v2);
 println(degrees(a));  
 
float  posX = x2+cos( a ) * -20;
float posY =y2+ sin( a ) * -20;
ellipse(posX,posY,4,4);

float  posX2 = x2+cos( a ) * 20;
float posY2 =y2+ sin( a ) * 20;
ellipse(posX2,posY2,4,4);

}




Re: How to calculate these points. 3d space
Reply #3 - Nov 5th, 2009, 6:17am
 
goto www.pixelnerve.com/v and search for "mesh".

you will find code for Ribbon Mesh which has a method inside that builds a cylinder along a path (which you already have) or if you prefer there is a cooler version in the Arcs source code.

the method name would be something like - renderCylinderFromBuffer( ArrayList buf ); -

if you just want the quad strip , you can use the same, just tell the number of points the cylinder should have, or look for the -renderTail()- method. it renders flat strips.

have fun
Re: How to calculate these points. 3d space
Reply #4 - Nov 5th, 2009, 6:41am
 
ahh nice, you prefer documentation.

so you have a path. that path is segmented.

for each segment take the direction vector, T = path[i+1] - path[i];

you need two vector to get a third perpendicular vector and with all 3 build a local coordinate system. so you need to find a new vector to cross product with T.

what i do is usually use the up vector (0, 1, 0) but that have some problems and i found other solution which is adding the two segment points. so N = path[i+1] + path[i];

(in case you need it, you can check both vectors and see if they dont coalign, if so happens you need to find another.)

now you have two vectors, cross product and you will get a new vector called B.

(you almost have your system prepared)
now you know T and B are perpendicular, so you can take cross product between them and get the new N based on those two vectors.

with all that you have:

T = path[i+1] - path[i];
N = path[i+1] + path[i];

T.normalize();
N.normalize();
B = T.cross( N );
N = B.cross( T );

this means you have the all 3 coord-system vectors defining your local space at each vertex of your path. from here render a circle of points with the detail you want and rotate them by the matrix defined by TBN.

that will do, for more information you better visit the code or read more on building the mesh from here.

hope i was clear enough..
have fun.
Re: How to calculate these points. 3d space
Reply #5 - Nov 5th, 2009, 6:49am
 
Thx for your help V, i accidential deleted my post. But i will work through it and try to figure it out.
Re: How to calculate these points. 3d space
Reply #6 - Nov 6th, 2009, 1:01pm
 
Allright, i gave my best so far but i am stuck again.
First thanks again for your explanation. I bet it was good, im just missing some basic knowledge here.
i used the test sketch above to test it first.
but there are serveral things that i am not sure of if i understood them right. the path[i+1]-path[i] looks similar to what i have allready done. But is that how you ment it? taking the segmentpoints and substract them to get the vector?

next thing was calculating TBN. thats looks ok to me.
But how can i use these 3 vectors to rotate the points ?
and rotating using roateX rotateY... doesnt work cause i need coordinates right? so i need to calculate them somehow.

Could you take a look and tell me what i miss or just do wrong...
thank you!

Code:
void setup(){
size(400,600,P3D);
}

void draw(){
float x1 = 100;
float y1 = 100;
float z1 = 0;
float x2 = 100;
float y2 = 300;
float z2 = 0;
float x3 = mouseX;
float y3 = mouseY;
float z3 = 0;

background(255);
stroke(0);

line(x1,y1,z1,x2,y2,z2);
line(x2,y2,z2,x3,y3,z3);

PVector T = new PVector(x3-x2,y3-y2,z3-z2);
PVector N = new PVector(x3+x2,y3+y2,z3+z2);

T.normalize();
N.normalize();

PVector B = T.cross(N);
N = B.cross(T);

}

Re: How to calculate these points. 3d space
Reply #7 - Nov 7th, 2009, 4:44pm
 
Ok, this is probably kind of a hack as it is not supposed to be used this way, but it works great.

So I used bezierTangent to get the perpendicular Points i needed. Important not to set t to 0 and 1 but to 0.001 and 0.009

here is my code. it seems to be a bit tricky to port it from 2d to 3d though, but it seems to work in my case too.

Code:
void setup(){
size(400,400);
}

void draw(){
background(255);

float x2 = lerp(mouseX,150,0.999);
float y2 = lerp(mouseY,80,0.999);
float x = lerp(mouseX,150,0.001);
float y = lerp(mouseY,80,0.001);
float tx = bezierTangent(mouseX, mouseX, 150, 150,0.5);
float ty = bezierTangent(mouseY, mouseY, 80,80,0.5);
float a = atan2(ty, tx);

a -= HALF_PI;

stroke(255,0,0);
line(150,80,mouseX,mouseY);
stroke(0);
fill(0,40);
beginShape(QUAD_STRIP);
vertex(cos(a)*18 + x, sin(a)*18 + y);
vertex(cos(a)*-18 + x, sin(a)*-18 + y);
vertex(cos(a)*18 + x2, sin(a)*18 + y2);
vertex(cos(a)*-18 + x2, sin(a)*-18 + y2);
endShape();
}
Page Index Toggle Pages: 1