if you use these vectors to calculate a cross product:

Vector3d vec1 = new Vector3d(x1-x2, y1-y2, z1-z2);
Vector3d vec2 = new Vector3d(x1-x2, y1-y2, z1-z2-1.0); <-- ?? right?

the vectors can be paralel ( x1 == x2 && y1 == y2). This leaves you with a
null crossproduct(0,0,0).

What should be the direction the normal vector? Could you tell me the idea
behind this? Is the point to generate an arrow in a default place/direction
and then use a linear transform to translate/rotate it to the right
place/direction? If this is true, it might be better to use a constructor of
Transform3D that takes a rotation matrix and a translation vector. By the
way, why do you use vectors to define the begin and endpoint of your arrow?
would like to help, but i use my own linear algebra package (not vecmath).

Lars


-----Original Message-----
From: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED] Behalf Of Horst Sueggel
Sent: maandag 26 april 2004 19:48
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] lookAt method


Thank you very much for the answer.
But i have still the following problem:

I have 2 Points given and i have to draw an arrow between point1 to point2.
So i have tried to solve my problem with the lookAt method.
But it seems that i haven't implemented my arrow in a right way.

My sample code:


private Transform3D calculateRotationTransform3D(Vector3d source, Vector3d
target){
 // source position
 double x1 = source.x;
 double y1 = source.y;
 double z1 = source.z;
 // target position
 double x2 = target.x;
 double y2 = target.y;
 double z2 = target.z;
 // arrow length
 double len = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) +
(z1-z2)*(z1-z2));


 //middle of the two positions ( = position of arrow)
 double x_middle = (x1+x2)/2;
 double y_middle = (y1+y2)/2;
 double z_middle = (z1+z2)/2;
 //
 Point3d eye = new Point3d(x_middle, y_middle, z_middle);

 // calculate temp normal vector (cross product)<-- i dont know if this is
right
 Vector3d vec1 = new Vector3d(x1-x2, y1-y2, z1-z2);
 Vector3d vec2 = new Vector3d(x1-x2, y1-y2, z1-z2-1.0); <-- ?? right?
 Vector3d normalVec = new Vector3d();
 normalVec.cross(vec1, vec2);

 Vector3d temp = new Vector3d(normalVec);
 temp.normalize();
 temp.scale(len/2.0d);

 Vector3d centerVec = new Vector3d();
 centerVec.add(new Vector3d(x_middle, y_middle, z_middle));
 //centerVec.add(temp);
 normalVec.negate();
 centerVec.add(normalVec);
 Point3d center = new Point3d(centerVec.x, centerVec.y, centerVec.z);


 // Vector3d v1 = new Vector3d(x1-x2, y1-y2, z1-z2);
 Vector3d v1 = new Vector3d(x_middle-normalVec.x, y_middle-normalVec.y,
z_middle-normalVec.z);
 Vector3d v2 = new Vector3d(x_middle-normalVec.x, y_middle-normalVec.y,
z_middle-normalVec.z-1.0d);
 Vector3d normal = new Vector3d();
 normal.cross(v1, v2);


 Transform3D rot = new Transform3D();
 rot.lookAt(eye, center, normal);
 rot.invert();

 return rot;
    }

the call:
.
.
.
Transform3D caTransform = calculateRotationTransform3D(stPt, endPt);
TransformGroup caTransformGroup = new TransformGroup(caTransform);

Node cArrowCylinder = new Cylinder((float)ArrowDia, (float)CylenderLen,
caAppearance);
Transform3D caTransform = calculateRotationTransform3D(stPt, endPt);
TransformGroup caTransformGroup = new TransformGroup(caTransform);
.
.
.
Node cArrowCylinder = new Cylinder((float)ArrowDia, (float)CylenderLen,
caAppearance);

I would appreciate if you can verify or correct this code

Greets,
Horst Sueggel

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to