Sorry, Chris, I failed to provide anything useful except agreeing with what
you said.

I imagine there are other ways to do this, but I just added a check to see
if the cross product went to zero, then chose another "up" vector.  It is
not very elegant in my estimation, but I think it is okay since the idea
appears to be to create a set of orthogonal vectors to define a frame that
has the forward axis pointing along the path between two points of the line.
There are other ways to do this, maybe using AxisAngle with the translation,
but I haven't looked into what the trade-offs are.

As for the two points situation, I'm not sure what the vertex you are
printing is, but, as I mentioned last time, the segments being calculated
will be the same for only two points.  I haven't tried to actually run it,
but it appears from the code that the tube should still be created
(although, with only two points, it won't be much of a torus, if that was
what you were looking for).

And for my change that I added for the "if" statement, it would actually
seem to me that the final segment is not needed for an open loop.

        Thoughts?

        Chet Urata



-----Original Message-----
From: Discussion list for Java 3D API
[mailto:[EMAIL PROTECTED] Behalf Of Chet Urata
Sent: Friday, July 25, 2003 3:00 PM
To: [EMAIL PROTECTED]
Subject: Re: [JAVA3D] 3D line to 3D tube


Greetings, Chris,

        Although the points (1,1,0) and (2,2,0) are not parallel to the
z-axis,
your point is correct.  Good catch!  The code does fail when two points are
parallel to the z-axis because of the cross product of the direction vector
with the vector (0, 0, 1).  We need to find a work-around.

        And it is indeed problematic for the algorithm when using only two
points.
If you follow the code, you'll notice something:

Consider the two values for i, 0 and 1:

i == 0: forward.sub(path[1],path[0])
i == 1: forward.sub(path[1],path[0]) // because (i == (segs-1)) for either
closed or open loops

They look mighty similar.

I also had a problem with the code

>                         if closed  : forward.sub(path[i],path[i-1])
>                         else       : forward.sub(path[1],path[0])

changing it to something like

>                         if closed  : forward.sub(path[0],path[i])
>                         else       : forward.sub(path[i],path[i-1])

        Chet Urata




--- Chris Fenton <[EMAIL PROTECTED]> wrote:
> Some notes on code.
> Code fails when consective path points are parallel to Z axis (1,1,0)
> (2,2,0).
> But more mysteriously the translational part of the transform does
> not seem to be working look at the following.
>
> def CreateTube(path,radius,steps,closed=0):
>      ---create circle ---
>      for i in range(segs):
>                 forward, right = Vector3d(), Vector3d()
>                 if i != segs-1: forward.sub(path[i+1],path[i])
>                 else               :
>                         if closed  : forward.sub(path[i],path[i-1])
>                         else       : forward.sub(path[1],path[0])
>                 forward.normalize()
>                 up           = Vector3d(0.0,0.0,1.0)
>                 right.cross(forward, up)
>                 up.cross(forward, right)
>                 frenetmatrix = Matrix3d(right,up, forward)
>                 trans        = Transform3D(frenetmatrix, Vector3d(),
> 1)
>                 trans.setTranslation(path[i])
>                 for k in range(steps):
>                         tempvert = Vector3d()
>                         trans.transform(circle[k], tempvert)
>      ---print ---
>
>
> Input :
>         path   = ((1,1,1),(2,2,2))
>         total  = CreateTube(path, 0.5, 3, 1)
>
> Notice:
>
> Path = (1,1,1), circle(0.5,0,0), vertex(0.288-, 0.166-, 0.288-)
> Path = (2,2,2), circle(0.5,0,0), vertex(0.288-, 0.166-, 0.288-)
>
> HOW IS THIS POSSIBLE WITH DIFFERENT TRANSLATIONAL COMPONENTS ?
>
> Output :
>
>
> trans ------------------------------
> 0.5773502691896258, -0.5773502691896258, 0.0, 1.0
> 0.3333333333333334, 0.3333333333333334, -0.6666666666666669, 1.0
> 0.5773502691896258, 0.5773502691896258, 0.5773502691896258, 1.0
> 0.0, 0.0, 0.0, 1.0
>
> point (1.0, 1.0, 1.0)
> circle (0.5, 0.0, 0.0)
> vertex (0.2886751345948129, 0.1666666666666667, 0.2886751345948129)
>
>
> trans ------------------------------
> 0.5773502691896258, -0.5773502691896258, 0.0, 2.0
> 0.3333333333333334, 0.3333333333333334, -0.6666666666666669, 2.0
> 0.5773502691896258, 0.5773502691896258, 0.5773502691896258, 2.0
> 0.0, 0.0, 0.0, 1.0
>
> point (2.0, 2.0, 2.0)
> circle (0.5, 0.0, 0.0)
> vertex (0.2886751345948129, 0.1666666666666667, 0.2886751345948129)
>
>
===========================================================================
> 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".

===========================================================================
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