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".