Part authoring scripts and tools


Re: Part authoring scripts and tools
#3
This perl script creates the intersection between a cylinder and a plane at a given radius, segments and angle

Code:
use Math::Trig; ## Computes the intersection between a cylinder ## and the yz-plane. ## Radius $rad at $theta angle with $segs segments $pi=3.141592635; $d2r=$pi/180; ## Specify number of segments, angle, radius $segs=16; #$theta=34.742*$d2r; $theta=(90-34.742)*$d2r; $rad=4; ## Masks $linemask="2 24 %.2f %.2f %.2f %.2f %.2f %.2f\n"; $optmask="5 24 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n"; $trimask="3 16 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n"; $quadmask="4 16 %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f %.2f\n"; foreach $n (0..($segs-1)) { $phi=$n/$segs*2*$pi; $yeff=(1-cos($phi))*$rad; $xeff=sin($phi)*$rad; $x1=$xeff; $y1=$yeff*sin($theta); $z1=$yeff*cos($theta); $x2=$xeff; $y2=0; $z2=$yeff/cos($theta); $pts1->[$n]=[$x1,$y1,$z1]; $pts2->[$n]=[$x2,$y2,$z2]; } foreach $n (0..($segs-1)) { $np=($n<($segs-1))?($n+1):0; $nm=($n>0)?($n-1):($segs-1); $x10=$pts1->[$n][0]; $y10=$pts1->[$n][1]; $z10=$pts1->[$n][2]; $x20=$pts2->[$n][0]; $y20=$pts2->[$n][1]; $z20=$pts2->[$n][2]; $x1p=$pts1->[$np][0]; $y1p=$pts1->[$np][1]; $z1p=$pts1->[$np][2]; $x2p=$pts2->[$np][0]; $y2p=$pts2->[$np][1]; $z2p=$pts2->[$np][2]; $x1m=$pts1->[$nm][0]; $y1m=$pts1->[$nm][1]; $z1m=$pts1->[$nm][2]; $x2m=$pts2->[$nm][0]; $y2m=$pts2->[$nm][1]; $z2m=$pts2->[$nm][2]; printf($linemask, $x20, $y20, $z20, $x2p, $y2p, $z2p); if (($x10!=$x30) || ($y10!=$y30) || ($z10!=$z30)) { printf($optmask, $x10, $y10, $z10, $x20, $y20, $z20, $x1p, $y1p, $z1p, $x1m, $y1m, $z1m); printf($quadmask, $x1p,$y1p,$z1p,$x10,$y10,$z10, $x20,$y20,$z20,$x2p,$y2p,$z2p); } else { printf($trimask, $x1p,$y1p,$z1p,$x10,$y10,$z10, $x2p,$y2p,$z2p); } }
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Re: Part authoring scripts and tools - by Tim Gould - 2011-08-03, 23:10

Forum Jump:


Users browsing this thread: 1 Guest(s)