Utility search


Re: Utility search
#4
This perl script might do the trick. Given two points and a radius it will return the type 1 line to draw a cylinder of radius rad between the two points.

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"
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Utility search - by Kevin Roach - 2012-09-12, 13:56
Re: Utility search - by Philippe Hurbain - 2012-09-12, 15:56
Re: Utility search - by Michael Heidemann - 2012-09-13, 19:01
Re: Utility search - by Kevin Roach - 2012-09-14, 8:15
Re: Utility search - by Tim Gould - 2012-09-13, 22:14
Re: Utility search - by Kevin Roach - 2012-09-14, 7:56
Re: Utility search - by Tim Gould - 2012-09-14, 8:43
Re: Utility search - by Kevin Roach - 2012-09-14, 15:51
Re: Utility search - by Tim Gould - 2012-09-14, 20:48
Re: Utility search - by Kevin Roach - 2012-09-15, 5:32
Re: Utility search - by Tim Gould - 2012-09-15, 7:33

Forum Jump:


Users browsing this thread: 1 Guest(s)