I was wondering if there is a utility that can generate a cylinder of a given radius, centered on the line between two points. If I had this would be so helpful. The cylinder result would come out as an n-ncyli.dat file. Generated from the first point with the same orientation as the line.

**Utility search**

Code:

`sub help {`

print "

Usage: CyliPoints.pl x1 y1 z1 x2 y2 z2 rad

(all points must be specified)

Returns the ldraw code for a cyli prim of radius rad

pointing from (x1,y1,z1) to (x2,y2,z2)

";

}

use Math::Trig;

$pi=3.141592635;

sub pointstr {

my ($x,$y,$z)=@_;

return sprintf("%.3f %.3f %.3f ", $x, $y, $z);

}

sub matstr {

my ($M11,$M12,$M13,$M21,$M22,$M23,$M31,$M32,$M33)=@_;

return sprintf("%.4f %.4f %.4f ", $M11, $M12, $M13)

.sprintf("%.4f %.4f %.4f ", $M21, $M22, $M23)

.sprintf("%.4f %.4f %.4f ", $M31, $M32, $M33);

}

sub dot {

my ($x1,$y1,$z1,$x2,$y2,$z2)=@_;

return ($x1*$x2+$y1*$y2+$z1*$z2);

}

sub norm {

my ($x,$y,$z)=@_;

$r=sqrt($x*$x+$y*$y+$z*$z);

if ($r>1e-5) {

return ($x/$r,$y/$r,$z/$r,$r);

} else {

return (0,1,0,0);

}

}

if ($#ARGV<6) { &help(); exit; }

my ($x1,$y1,$z1,$x2,$y2,$z2,$rad)=@ARGV;

my $dx=$x2-$x1;

my $dy=$y2-$y1;

my $dz=$z2-$z1;

$rxz=sqrt($dx*$dx+$dz*$dz);

my ($xn,$yn,$zn,$rn)=&norm($dx,$dy,$dz);

my ($xp,$yp,$zp,$rp)=&norm($rxz,$dy,0);

my ($xnp,$ynp,$znp)=&norm($dx,0,$dz);

my ($xpp,$ypp,$zpp)=&norm($xp,0,$zp);

$angxy=&acos(&dot(0,1.0,0,$xp,$yp,$zp));

$angxz=&acos(&dot($xnp,0,$znp,$xpp,0,$zpp));

printf("0 // Angle in xy plane: %.4f\n",$angxy/$pi*180.0);

printf("0 // Angle in xz plane: %.4f\n",$angxz/$pi*180.0);

$c1=cos($angxy);

$s1=sin($angxy);

$c2=cos($angxz);

$s2=sin($angxz);

$M11=$c1*$c2*$rad;

$M12=$s1*$c2*$rn;

$M13=-$s2*$rad;

$M21=-$s1*$rad;

$M22=$c1*$rn;

$M23=0;

$M31=$c1*$s2*$rad;

$M32=$s1*$s2*$rn;

$M33=$c2*$rad;

print "1 16 ".&pointstr($x1,$y1,$z1)." "

.&matstr($M11,$M12,$M13,$M21,$M22,$M23,$M31,$M32,$M33)

."4-4cyli.dat\n"

The one does do precisely what you ask.

If you're using windows you could install ActivePerl. If you then download the script and save it with a .pl extension it should just run from the command prompt.

Tim

The main software I use in authoring a part is: Turbo Cad and Microsoft Excel. With Turbo Cad I can draw what I need and pull the points off the drawing. But it is only 2D. This makes what I am doing difficult.

ie.

1) Go to notepad

2) Copy the code from above and paste it into notepad\

3) Save as CyliPoints.pl in a directory [DIR] you can get to easily

4) Open a command prompt and cd to [DIR]

5) Just type "CyliPoints.pl X1 Y1 Z1 X2 Y2 Z2 Rad" at the command prompt and copy the output

Tim

**« Next Oldest | Next Newest »**

Users browsing this thread: 1 Guest(s)