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 Graph (Read 1188 times)
3D Graph
Apr 18th, 2006, 9:50am
 
Hi Folxs,

I implemented an 2D directed Graph in processing and work at the 3D. I can draw the nodes and all edges in 3D, no problem. But now i want also draw (like in 2D) Arrows from one Node to another.

Problem:
I know the Start and End of a line. I realized the Nodes as spheres. I can calculate the point, where the 3D-Arrow (cone) intersects the sphere. But i didnt get it to rotate the drawn cone in one axis in the right position. I surely use pushMArtix and popMatrix. I get it to place the cone correctly in one plane, i.e. XY or ZX. But all three i didnt get. I know the new axis where the cone has to be, but cant make it to rotate to that position.

I feel embarrassed that i didnt get it. I tried since three days the rotation and now i am rotating, but not the cones.
Can you help me or show me an example, where two points in xyz are connected with one Object which is placed between them by rotating?

Regards,
Matthias

PS: I study ten years in natural science and now cant rotate an object in 3d. Why the hell i study?
Re: 3D Graph
Reply #1 - Apr 18th, 2006, 11:17am
 
What you need is something like:

Code:
float angleY=atan2(zDifference,xDifference);
float angleZ=atan2(yDifference,sqrt(sq(xDifference)+sq(zDifference)));
rotateY(angleY);
rotateZ(angleZ);


Where x/y/zDifference are the differences in the x/y/z axes between the 2 points.

That'll let you draw along the line of the arrows, as if it's horizontal (I think).
Re: 3D Graph
Reply #2 - Apr 18th, 2006, 2:49pm
 
Now xy lies in the same plane like the connection btw. the two points. How did i find the vector in xy-pane which draw on line?
Re: 3D Graph
Reply #3 - Apr 18th, 2006, 4:19pm
 
If you do the calculation I posted, YZ will be perpendicular to the vector from point 1 to point 2, so you just need to do:

Code:

//Calculate vector length along each axis;
float xDifference=point2xpos-point1xpos;
float yDifference=point2ypos-point1ypos;
float zDifference=point2zpos-point1zpos;

//find distance between the 2 points
float length=sqrt(sq(xDifference)+sq(yDifference)+sq(zDifference));

//move (0,0,0) so that it'll be at the first point
translate(point1xpos,point1ypos,point1zpos);

// First rotate, about the Y axis;
float angleY=atan2(zDifference,xDifference);
rotateY(angleY);

//Second rotate, about the Z axis;
float
angleZ=atan2(yDifference,sqrt(sq(xDifference)+sq(zDifference)));
rotateZ(angleZ);

//draw cone from 0,0,0 to length,0,0
//temporary filler, I don't know how your cone drawing works...
beginShape(LINES);
vertex(0,0,0);
vertex(length,0,0);
endShape();
Re: 3D Graph
Reply #4 - Apr 18th, 2006, 5:16pm
 
yes z is perpedicular to the vector. I draw the cone on z:

beginShape(TRIANGLES);
for (int i = 0; i <= 12; i++) {
float a1 = PI / 6 * i, a2 = PI / 6 * (i + 1);
vertex(0, 0, 0);
vertex(arrowSize / 4 * cos(a1), arrowSize / 4 * sin(a1), -arrowSize);
vertex(arrowSize / 4 * cos(a2), arrowSize / 4 * sin(a2), -arrowSize);
}
for (int i = 0; i <= 12; i++) {
float a1 = PI / 6 * i, a2 = PI / 6 * (i + 1);
vertex(0, 0, -arrowSize);
vertex(arrowSize / 4 * cos(a1), arrowSize / 4 * sin(a1), -arrowSize);
vertex(arrowSize / 4 * cos(a2), arrowSize / 4 * sin(a2), -arrowSize);
}
endShape();

But as you mentioned Z is 90 degrees to the vector, so i need to draw the cone on xy. how do i estimate the position of the inner coords in xy, so that the drawing is correct to the outer vector?

regards,
Matthias
Re: 3D Graph
Reply #5 - Apr 19th, 2006, 11:59am
 
To go from perpendicular to XY to perpendicular to YZ, just swap the x/z parts of the vertex( ) functions, and it should just work.

Page Index Toggle Pages: 1