This perl script creates a corner between two cylinders at arbitrary angle, segments and radius.
Code:
use Math::Trig;
## Computes the corner between two cylinders
## or radius $rad at $theta angle with $segs segments
$pi=3.141592635;
$d2r=$pi/180;
## Specify number of segments, angle, radius
$segs=16;
#$theta=55.238*$d2r;
$theta=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";
# Internal variables
$thetah=$theta/2;
foreach $n (0..($segs-1)) {
$phi=$n/$segs*2*$pi;
$yeff=(1-cos($phi))*$rad;
$xeff=sin($phi)*$rad;
$x1=$xeff;
$y1=$yeff;
$z1=0;
$x2=$xeff;
$y2=$yeff;
$z2=$yeff*tan($thetah);
$x3=$xeff;
$y3=$yeff*cos($theta);
$z3=$yeff*sin($theta);
$pts1->[$n]=[$x1,$y1,$z1];
$pts2->[$n]=[$x2,$y2,$z2];
$pts3->[$n]=[$x3,$y3,$z3];
}
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];
$x30=$pts3->[$n][0];
$y30=$pts3->[$n][1];
$z30=$pts3->[$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];
$x3p=$pts3->[$np][0];
$y3p=$pts3->[$np][1];
$z3p=$pts3->[$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];
$x3m=$pts3->[$nm][0];
$y3m=$pts3->[$nm][1];
$z3m=$pts3->[$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($optmask,
$x30, $y30, $z30, $x20, $y20, $z20,
$x3p, $y3p, $z3p, $x3m, $y3m, $z3m);
printf($quadmask,
$x1p,$y1p,$z1p,$x10,$y10,$z10,
$x20,$y20,$z20,$x2p,$y2p,$z2p);
printf($quadmask,
$x2p,$y2p,$z2p,$x20,$y20,$z20,
$x30,$y30,$z30,$x3p,$y3p,$z3p);
}
else {
printf($trimask,
$x1p,$y1p,$z1p,$x10,$y10,$z10,
$x2p,$y2p,$z2p);
printf($trimask,
$x2p,$y2p,$z2p,
$x30,$y30,$z30,$x3p,$y3p,$z3p);
}
}