Utility search


Utility search
#1
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.
Reply
Re: Utility search
#2
Do you want to use a single cyli primitive (in this case I have nothing to offer... except a bit of trig calculations!), or build a cylindrical tube with curved path? in the later case, my PathTruder utility will do the trick.
Reply
Re: Utility search
#3
Why not using standard cyl primitives?
Also if you need customized primitives you can give PrimGen2 a try.

I hope I have understand your request correctly.
Reply
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
Re: Utility search
#5
Thank you for the Perl script. It would be extremely helpful if knew anything about Perl. Or scripts in general. That type of programming I am not quite clear on. I tried to learn C++ years ago. But did not stay with it long enough to fully absorb the concept.
Reply
Re: Utility search
#6
Imagine you have two points not on the same plane. Ex (-5.477,-45.783,260.680) and (13.732,-13.601,231.425). And you want a cylinder that runs from one point to the other. So I need something that would generate the orientation for the primitive 4-4cyli.dat starting from one of the given points. End at the other point.
Reply
Re: Utility search
#7
Ahhh. I figured you must have been scripting to generate your parts.

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
Reply
Re: Utility search
#8
Who? What? Well I downloaded Active Perl. But download the script from where? And open it with what? In my mind I need to open it with something to save it as a .pl file. I am sorry, but I literally know nothing about all of this.

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.
Reply
Re: Utility search
#9
Sorry, I meant just copy it straight from my post, paste it to 'CyliPoints.pl' (or something) and then run it.

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
Reply
Re: Utility search
#10
Thank you. This is just what I needed.
Reply
Re: Utility search
#11
I believe it might have problems if Y2<Y1. In that case switch the two points around.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)