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 & HelpOpenGL and 3D Libraries › Arc between two points in 3D?
Page Index Toggle Pages: 1
Arc between two points in 3D?? (Read 1192 times)
Arc between two points in 3D??
Dec 6th, 2005, 8:40pm
 
I have to calculate an arced path for a point, from one point to another.

The points are positioned in a spherical maner, and the arc should be pointing away from (0,0,0)..
Code:

,'`,
*a | '
\ |D \
\| |
C---*---'--- midpoint
...\ '
....\ '
.....*b

C is the crossproduct
D is the up angle.. the direction of the point, away from the center of the sphere of points

any help on this matter would be grately appreciated
Re: Arc between two points in 3D??
Reply #1 - Dec 8th, 2005, 5:28pm
 
Let V1 and V2 two vectors.
If V1.length=V2.length=r
then
  alpha=Math.acos( dot(V1/r,V2/r))  (radians)
  arc=alpha*r.
Re: Arc between two points in 3D??
Reply #2 - Dec 9th, 2005, 5:17pm
 
That wasn't very explanatory for me unfortunatly..

I need x,y,z variables ..
i have this function, which does the job, but not rotated correctly:

Code:

void drawArc(P a, P b, int step, int maxstep)
{
float x, y, z;
P C = a.CenterPoint(b); // the centerpoint of a and b
C.draw(2); // draws the current centerpoint size 2
float div = PI/maxstep; // number of steps
for(int i = 0; i < maxstep; i++)
{
pushMatrix();
translate(C.x,C.y,C.z); // so it rotates around C
stroke(0,255,0);
x = (cos(div*i)*(C.Distance(b)));
y = (sin(div*i)*(C.Distance(b)));
z = 0;
point(x,y,z);
popMatrix();
}
}


Basicly, all i need to get this to work is:
total Centerpoint (0,0,0)
Point 1
Point 2
CenterPoint

Then to get the direction of the arc i take
CenterPoint+CenterPoint/10 // since it's away from (0,0,0)

That's about where it stops for me..
I did some rotating with rotateX,Y,Z but couldn't really see what angles to calculate to get the correct rotation.

again, any pointers would be greatly appreciated

-seltar
Re: Arc between two points in 3D??
Reply #3 - Dec 9th, 2005, 7:27pm
 
I was going to pick it out of the code for you and explain it properly but I really should be cracking on with my thesis.

http://www.hardcorepawn.com/Anenome/

JohnG's anenome has a cylinder building class which uses calculations of pitch and heading to work out the trigonometry. You might want to experiment by pulling the equations out of his class and experimenting with them. They're pretty solid for modelling trajectory as I've used the cylinder builder for a project that exports .obj files.

Another idea would be to model your arc using a bezier curve. You could then track points along that arc using bezierPoint(). That would be the least headache method.
Re: Arc between two points in 3D??
Reply #4 - Dec 9th, 2005, 10:20pm
 
please see:
http://www.alcys.com/p5/TracerArc/applet/index.html

Code:


public void tracerArc(Vecteur v1,Vecteur v2){
Vecteur v3=new Vecteur();
float angle=(float)Math.acos(v2.dot(v1)/v2.dot(v2));
for(float t=0;t<=1;t+=0.05f){
v3=Vecteur.comb(sin((1-t)*angle)/sin(angle),v1,sin(t*angle)/sin(angle),v2);
line(0,0,0,v3.x,v3.y,v3.z);
}

}
Re: Arc between two points in 3D??
Reply #5 - Dec 10th, 2005, 12:23am
 
Thank you both so much!
I got it working using the bezierPoint();

you can see it in action here:
http://seltar.wliia.org/sketch.php?pid=33
Smiley

woohoo

-seltar
Page Index Toggle Pages: 1