Drawing a cylinder from A to B


Drawing a cylinder from A to B
#1
I wish to use the primitive 'cyli.dat' to draw a cylinder from one arbitrary point in 3-space to another arbitrary point in 3-space, ie from (X1,Y1,Z1) to (X2,Y2,Z2) - the points being the centres of the circles defining the two ends of the cylinder. It will have a fixed diameter which I can code in the primitive.

I therefore need a general algorythm which will produce a suitable transformation matrix - I realise there may be more than one, anything that works would do!

I am getting old and slow and understanding transformation matricies is now beyond me - I need the help of a young wiz-kid!

Please!
Reply
Re: Drawing a cylinder from A to B
#2
Hi Wolstan,

Define
RX=X2-X1
RY=Y2-Y1
RZ=Z2-Z1

R1=sqrt(RX*RX+RZ*RZ);
R3=sqrt(RX*RX+RY*RY+RZ*RZ)

V1X=-RZ/R1
V1Y=0
V1Z=RX/R1

V2X=RX*RY/R1/R3
V2Y=-R1/R3
V2Z=RY*RZ/R1/R3

V3X=RX
V3Y=RY
V3Z=RZ

Now you can define

1 16 X1 Y1 Z1 V1X V2X V3X V1Y V2Y V3Y V1Z V2Z V3Z cyli.dat

which should (I hope) work.

All the best,

Tim
Reply
Re: Drawing a cylinder from A to B
#3
R1 will cause division by zero problems if only Y differs between the two points.

@Wolstan Dixie: This problem sounds like you are trying to do path plotting, so (me being curious) what do you need this algorithm for? As there might already be solutions like LSynth for it out there.
Reply
Re: Drawing a cylinder from A to B
#4
Well - I'll come clean. I don't actually want to construct anything in virtual Lego, I want to use the LDraw and LDView programmes to construct and view a large complex of pipes writhing through space, for which I have the (x,y,z) of each change of direction. I don't mind the joins won't be perfect. Is this 'path plotting'? and is there a better way of doing it?
Reply
Re: Drawing a cylinder from A to B
#5
Roland Melkert Wrote:R1 will cause division by zero problems if only Y differs between the two points.

Yes. There should be a special case for RX=RX=0. In that case

1 16 X1 Y1 Z1 1 0 0 0 0 -1 0 RY 0 cyli.dat

should work.

Tim
Reply
Re: Drawing a cylinder from A to B
#6
Many thanks, I appreciate it - I'll try it this evening!
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 3 Guest(s)