I have a problem I'm trying to figure out here. I can see intuitively how
to do it but not mathmatically.
I have two cylinders (pipes actually) that I'm trying to draw an "arrow"
between to show flow direction. So, what I really have is 2 3D points.
(Transformation matricies actually, but only containing translation.)
Call these two points, A and B.
And what I want to do is, create a standard "arrow" inside a transform
group and translate it to the midpoint of A and B, and rotate it such
that it "points" at B.
I've found an algorithm that does this 2 dimensionally. It leaves out
rotations about Y. Rather disturbing. I'll quote it at the end of the
mail.
The stop-gap mesure was to draw a line between the two points with a
linearray. But then the question of the "arrow heads" comes up.
I've got a solution that works "most" of the time, but you end up with
heads that could possibly be as long as the arrow itself.
(well, approaching that length.)
The rotation solution above would be ideal, since the "arrow",
(which represents a "junction") could actually be a valve. If its a
valve, then at some point I'm going to have to represent it as such
rather than a different color line. :P
Any help would be appreciated.
-John R.
-----------Excerpt from Arrow.java, stolen from j3d.org----------
float arrowDir = ((endPt.y-stPt.y)/Math.abs(endPt.y-stPt.y));
double lenSq = (stPt.x-endPt.x)*(stPt.x-endPt.x) +
(stPt.y-endPt.y)*(stPt.y-endPt.y) +
(stPt.z-endPt.z)*(stPt.z-endPt.z);
float ArrowLen = (float) Math.sqrt(lenSq);
float ArrowHeadLen = 5.0f*ArrowDia;
float ArrowHeadDia = 2.0f*ArrowDia;
float CylenderLen = ArrowLen - ArrowHeadLen;
//Rotation Matrix for whole arrow (cylinder + two cones)
Matrix4f RotMat = new Matrix4f();
float CosTheta = (endPt.x - stPt.x)/ArrowLen;
float SinTheta = (endPt.y - stPt.y)/ArrowLen;
RotMat.m00 = SinTheta;
RotMat.m01 = CosTheta;
RotMat.m02 = 0.0f;
// x translation
RotMat.m03 = stPt.x + (endPt.x - stPt.x)/2.0f - arrowDir*(ArrowHeadLen)/2.0f;
RotMat.m10 = -CosTheta;
RotMat.m11 = SinTheta;
RotMat.m12 = 0.0f;
// y translation
RotMat.m13 = stPt.y + (endPt.y - stPt.y)/2.0f - arrowDir*(ArrowHeadLen)/2.0f;
RotMat.m20 = 0.0f;
RotMat.m21 = 0.0f;
RotMat.m22 = 1.0f;
// z translation
RotMat.m23 = stPt.z + (endPt.z - stPt.z)/2.0f - arrowDir*(ArrowHeadLen)/2.0f;
RotMat.m30 = 0.0f;
RotMat.m31 = 0.0f;
RotMat.m32 = 0.0f;
RotMat.m33 = 1.0f;
===========================================================================
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".