#!/usr/local/bin/perl # perl script for Circular Tower With Structural Ring Support Rafter Calculations use CGI::Carp qw(fatalsToBrowser); #comment out this line when your done debugging this script $|++; #dont't buffer output #use strict; # file name:: circular-tower-ring.cgi # Created on Sunday, July 15, 2007 by Sim Ayers of SBE Builders # get latest version of this script at http://www.sbebuilders.com ################################################### # You are free to customize this script as you wish. # DISCLAIMER # The information and code provided is provided 'as is' without # warranty of any kind, either express or implied. In no event # shall the Company SBE Builders be liable for any damages whatsoever # including direct, indirect, incidental, consequential, loss of # business profits or special damages, even if the author has been # advised of the possibility of such damages. # DO NOT USE THIS SCRIPT UNLESS YOU CAN FULLY AGREE WITH THIS # DISCLAIMER. # copyright(C) 2007 ################################################### =head In a circle of radius r, the length of the chord that subtends a central angle x is r * sin( x/2). This script uses the theory of an polygon inscribed inside of a circle. So the radius is the run of the polygon hips and the chord is the length of the sides of the polygon. =cut my ($content_type_printed,%data,$back_wall,$projection,$face_wall,$pitch,$show_feet_inches); # print out perl headers to browser print "Content-type: text/plain\n\n" unless $content_type_printed++; &read_input(); #read user input variables if ($data{'radius'} eq ""){ # hand edit variables below for default values $radius = 96; $ring_radius = 24; $pitch = 8; $show_feet_inches = 'no'; $spacing = 8; $overhang = 24; $plate_width = 5.5; $fascia_width = 1.5; $ply_cut_off = 16; $hip_width = 3.5; $ring_width = 3.5; } else{ $radius = $data{'radius'}; $ring_radius = $data{'ring_radius'}; $pitch = $data{'pitch'}; $show_feet_inches = $data{'show_feet_inches'}; $spacing = $data{'spacing'}; $overhang = $data{'overhang'}; $plate_width = $data{'plate_width'}; $fascia_width = $data{'fascia_width'}; $ply_cut_off = $data{'ply_cut_off'}; $hip_width = $data{'hip_width'}; $ring_width = $data{'ring_width'}; } $radius = 12 if($radius < 12); $ring_radius = $radius if($ring_radius > $radius); $ring_radius = 1 if($ring_radius < 0); $hip_width = 1.5 if($hip_width < 0); $ring_width = 1.5 if($ring_width < 0); $spacing = 1 if($spacing < 0); #Global symbols # http://perldoc.perl.org/Math/Complex.html use Math::Complex qw(:trig); use POSIX qw(ceil floor); $PIE = 3.14159265358979323846; $RAD_TO_DEGREE = (180/pi); $DEGREE_TO_RAD = ($PIE/180); $RAD_TO_DEGREE45 = (0.785398163397448309616); $dxf_line_count = 100; $dxf_circle_count = 200; $arc_count = 300; $poly_line_count = 400; $DXF_STYLE=0; #dxf Line style $DXF_LAYER=0; #dxf file LAYER number $DXF_COLOR=0; # dxf line color $DXF_TSIZE=4.0; #dxf default dxf text size $DFX_LINE_TYPE = 1; $hip_count = 8; $half_the_thickness_of_the_hips = 0.75; # get geometry angles for circle $circumference = 2 * $PIE * $radius; $circumference_fascia_line = 2 * $PIE * ($radius + $overhang); $nsides = ceil($circumference / $spacing); $angle_deg = 360 / ($nsides *2); $hip_angle_deg = 360 / ($hip_count *2); $common_count = $nsides; $cord = 2 * $radius * sin(($angle_deg) * $DEGREE_TO_RAD); $cord_inside = 2 * ($radius - $plate_width) * sin(($angle_deg) * $DEGREE_TO_RAD); $cord_at_overhang = 2 * ($radius + $overhang - $fascia_width) * sin(($angle_deg) * $DEGREE_TO_RAD); $area = ($circumference * $radius) / 2; $arc_segment = $radius * ($angle_deg * $DEGREE_TO_RAD); $face_wall = (sin(22.5 * $DEGREE_TO_RAD)* $radius) * 2; $face_wall_half = $face_wall / 2; $span = ($face_wall_half / tan(22.5 * $DEGREE_TO_RAD)) * 2; #$face_wall = 2 * $radius * sin(($hip_angle_deg) * $DEGREE_TO_RAD); $run = $span / 2; $projection = sqrt( ($face_wall * $face_wall) / 2 ); $projection_offset = $projection; $projection_wall_angle_deg = 45; $projection_offset_wall_angle_deg = 90 - $projection_wall_angle_deg; $interior_wall_angle_deg = 135; $projection_wall_length = $projection_offset / cos($projection_wall_angle_deg * $DEGREE_TO_RAD); $half_projection_wall_length = $projection_wall_length / 2; $hip_rafter_run_bisect_angle_deg = $RAD_TO_DEGREE * atan($run / $face_wall_half); $pitch_angle = $RAD_TO_DEGREE * atan($pitch / 12); $Major_Pitch = atan($pitch / 12); $common_rafter_rise = $radius * ($pitch / 12); $common_rafter_length = $radius / cos(atan($pitch / 12)); $overhang_length = $overhang / cos(atan($pitch / 12)); $common_rafter_length_to_fascia = ($radius+$overhang) / cos(atan($pitch / 12)); $ring_offset_rafter = $ring_radius / cos(atan($pitch / 12)); $main_hips = $radius / cos(atan($pitch / 12)); $hip_ridge_deduction = $hip_width/2; $side_hips = ($radius - $hip_ridge_deduction) / cos(atan($pitch / 12)); $diag_ridge_deduction = hypot($hip_width/2,$hip_width/2); $side_45_hips = ($radius - $diag_ridge_deduction) / cos(atan($pitch / 12)); $ring_offset_diag = (cos(22.5 * $DEGREE_TO_RAD)* ($hip_width/2)); $ring_length = ((sin(22.5 * $DEGREE_TO_RAD)* $ring_radius) * 2) - ($ring_offset_diag*2); # Distance from center of circle to chord's midpoint: d # Chord length: c # Height: h $ring_length_no_deduction = ((sin(22.5 * $DEGREE_TO_RAD)* $ring_radius) * 2); $distance = (cos(22.5 * $DEGREE_TO_RAD)* $ring_radius); $h = $ring_radius - $distance; $ring_run = get_triangle_height($ring_radius,$ring_radius,$ring_length); $shorter_common_rafter = ($radius - $ring_radius) / cos(atan($pitch / 12)); $longer_common_rafter = ($radius - $ring_run) / cos(atan($pitch / 12)); # print "\n\n h = " .convertTOfeet($h); # print "\n\n distance = " .convertTOfeet($distance); # print "\n\n ring_length_no_deduction = " .convertTOfeet($ring_length_no_deduction); # print "\n\n "; $plywood_count = 0; $num_rows = ceil((($radius + $overhang) / cos(atan($pitch / 12)))/48); for($i=0; $i<$num_rows; $i++){ $circumference_row = 2 * $PIE * (($radius + $overhang - ((48 * $i) * cos(atan($pitch / 12))))); $count = ceil($circumference_row / (96 - $ply_cut_off)); $plywood_count += $count; #print "\n\n ply $i $count = " .convertTOfeet($circumference_row); #print "\n\n"; } print "Circular Tower With Structural Ring Rafter Calculations"; print "\nCalculations are rounded to the nearest 1/16 inch"; print "\n\n Radius of Tower = " .convertTOfeet($radius); print "\n\n Circumference of Tower Plate Line= " .convertTOfeet($circumference); print "\n\n Circumference At Fascia Line = " .convertTOfeet($circumference_fascia_line); print "\n\n\n Common Rafter Run = " .convertTOfeet($radius); print "\n\n Common Rafter Pitch = " .roundAngle($pitch); print "\n\n Common Rafter Pitch Angle = " .roundAngle($pitch_angle); print "\n\n Common Rafter Rise = " .convertTOfeet($common_rafter_rise); print "\n\n Common Rafter Length = " .convertTOfeet($common_rafter_length); print "\n\n Common Rafter Overhang Run = " .convertTOfeet($overhang); print "\n\n Common Overhang Rafter Length = " .convertTOfeet($overhang_length); print "\n\n Common Rafter Length To Fascia Line= " .convertTOfeet($common_rafter_length_to_fascia ); print "\n\n Common Rafter Spacing = " .convertTOfeet($spacing); print "\n\n Number of Common Rafters at $spacing'' O.C = " .$common_count; print "\n\n Common Rafter spacing at plate = " .convertTOfeet($cord); print "\n\n Common Rafter spacing at inside of plate = " .convertTOfeet($cord_inside); print "\n\n Common Rafter spacing at inside of fascia = " .convertTOfeet($cord_at_overhang); print "\n\n Plywood Roof Sheathing Cut Off Waste = " .$ply_cut_off; print "\n\n Plywood Roof Sheathing Count = " .$plywood_count; print "\n\n Fascia Width = " .$fascia_width; print "\n\n\n Octagon Hip Layout"; print "\n\n 45° Side Wall Projection = " .convertTOfeet($projection_offset); print "\n\n 45° Side Wall Projection Wall Length = " .convertTOfeet($projection_wall_length); print "\n\n 45° Side Wall Projection Wall Angle = " .roundAngle($projection_wall_angle_deg); print "\n\n Interior Wall Angle = " .roundAngle($interior_wall_angle_deg); print "\n\n Octagon Hip Rafter Run Bisect Angle = " .roundAngle($hip_rafter_run_bisect_angle_deg); print "\n\n Octagon Face Wall Length = " .convertTOfeet($face_wall); print "\n\n Octagon Span = " .convertTOfeet($span); print "\n\n Structural Ring Radius = " .convertTOfeet($ring_radius); print "\n\n Structural Ring Material Width= " .convertTOfeet($ring_width); print "\n\n Rafter Length From Center Of Ridge To Structural Ring Outside Edge = " .convertTOfeet($ring_offset_rafter); print "\n\n Structural Ring Length= " .convertTOfeet($ring_length)."±"; print "\n\n Structural Ring Side Cut Angle = " .roundAngle(22.5); $diag_ridge_deduction = roundAngle($diag_ridge_deduction); $hip_ridge_deduction = roundAngle($hip_ridge_deduction); print "\n\n\n Octagon Hips "; print "\n\n Octagon Hip Material Width = " .$hip_width; print "\n\n Full Length Hips To Plate Line = " .convertTOfeet($main_hips); print "\n\n Side Hips To Plate Line (Minus $hip_ridge_deduction Thickness Of Hips) = " .convertTOfeet($side_hips); print "\n\n 45° Hips To Plate Line (Minus $diag_ridge_deduction Run Of Hips) = " .convertTOfeet($side_45_hips); print "\n\n Longest Common Rafter To Structural Ring = " .convertTOfeet($longer_common_rafter)."±"; print "\n\n Shortest Common Rafter To Structural Ring = " .convertTOfeet($shorter_common_rafter)."±"; # text file with dxf header information $DXF_HEADER_FILE = "dxf_header.txt"; # text file to save dxf drawing to $DXF_File="circular-tower-ring.dxf"; #load dxf header file $dxf_header = get_dxf_header_file($DXF_HEADER_FILE); open(FILE, ">$DXF_File") || die("$DXF_File: Can't open because ($!)."); # add dxf header information to dxf output file print FILE "$dxf_header\n0\n"; # origin center in dxf document $originX = 100; $originY = 100; $theta = (2 * $PIE) / $nsides; $start_angle = $theta / 2; $x1 = $originX; $y1 = $originY; $radius2 = $overhang + $radius; $radius3 = $overhang + $radius - $fascia_width; # draw outside circumference circular plate dxf_circle($originX,$originY,$radius); # draw insidee circumference circular plate dxf_circle($originX,$originY,$radius - $plate_width); # draw outside circumference circular fascia line dxf_circle($originX,$originY,$radius2); # draw inside circumference circular fascia line dxf_circle($originX,$originY,$radius3); $theta = (2 * $PIE) / $hip_count; $start_angle = $theta / 2; dxf_hip_rect(0,$originX,$originY,$radius3,$hip_width); dxf_hip_rect($PIE,$originX,$originY,$radius3,$hip_width); dxf_hip_rect($PIE/2,$originX,$originY+($hip_width/2),$radius3 - ($hip_width/2),$hip_width); dxf_hip_rect($PIE*1.5,$originX,$originY-($hip_width/2),$radius3 - ($hip_width/2),$hip_width); $rad_angle = $PIE/4; dxf_hip_point_rect($rad_angle,$originX,$originY,$radius3,$hip_width); $rad_angle = 3*$PIE/4; dxf_hip_point_rect($rad_angle,$originX,$originY,$radius3,$hip_width); $rad_angle = 5*$PIE/4; dxf_hip_point_rect($rad_angle,$originX,$originY,$radius3,$hip_width); $rad_angle = 7*$PIE/4; dxf_hip_point_rect($rad_angle,$originX,$originY,$radius3,$hip_width); $arc_segment = $radius * $theta; $max = floor($arc_segment / $spacing); $angle = $theta / $max; $start_angle = atan($spacing / $radius ); # draw structural rings for($i=0; $i<$hip_count; $i++){ dxf_hip_ring_rect($theta * $i,$originX,$originY,$ring_radius,$ring_width,$theta,$hip_width); # draw common rafters for($j=0; $j<$max-1; $j++){ $x11 = $ring_radius * cos(($theta * $i) + $start_angle + ($angle * $j)); $y11 = $ring_radius * sin(($theta * $i) + $start_angle + ($angle * $j)); $x2 = $radius3 * cos(($theta * $i) + $start_angle + ($angle * $j)); $y2 = $radius3 * sin(($theta * $i) + $start_angle + ($angle * $j)); $x2 += $originX; $y2 += $originY; dxf_line($originX + $x11,$originY + $y11,$x2,$y2); } } $str= "ENDSEC\n0\nEOF"; print FILE $str; close FILE; exit; ################################### # library sub routines follow ################################### #=============================================================================# sub get_distance{ my ($x1,$y1,$x2,$y2) = @_; my $A = abs($x2 - $x1); my $B = abs($y2 - $y1); my $C = sqrt(sq($A) + sq($B)); #print "\n\n A = " .$A; #print "\n\n B = " .$B; return $C; } #=============================================================================# =head SAS -- Side, included Angle, and Side (Law of Cosines) SSA -- Two sides, and a non-included Angle (Law of Sines) AAS -- Any two angles, and one side (Law of Sines) C /\ / \ b / \a / h \ A /________\B c cos A = (b² + c² - a²) / 2*b*c cos B = (a² + c² - b²) / 2*a*c cos C = (a² + b² - c²) / 2*a*b a² = (b² + c²) - 2*b*c * cos A b² = (a² + c²) - 2*a*c * cos B c² = (a² + b²) - 2*a*b * cos C =cut #=============================================================================# sub get_triangle_height{ my ($side_a,$side_b,$side_c) = @_; my $cos_A = (sq($side_b) + sq($side_c) - sq($side_a)) / (2 * $side_b * $side_c); my $cos_B = (sq($side_a) + sq($side_c) - sq($side_b)) / (2 * $side_a * $side_c); my $cos_C = (sq($side_a) + sq($side_b) - sq($side_c)) / (2 * $side_a * $side_b); my $angle_A = acos($cos_A); my $height = sin($angle_A) * $side_b; return $height; } #=============================================================================# sub sq{ my ($side) = @_; return ($side * $side); } #=============================================================================# sub get_octagon_run{ my ($radius) = @_; my $face_wall = (sin(22.5 * $DEGREE_TO_RAD)* $radius) * 2; my $face_wall_half = $face_wall / 2; my $span = ($face_wall_half / tan(22.5 * $DEGREE_TO_RAD)) * 2; my $run = $span / 2; return $run; } #=============================================================================# sub dxf_hip_ring_rect{ my ($angle,$x1,$y1,$ring_radius,$ring_width,$theta,$hip_width) = @_; $poly_line_count++; my $radius = $ring_radius; my $radius2 = $radius - ($ring_width / cos(22.5 * $DEGREE_TO_RAD)); my $slope_angle = sin(($hip_width / 2) / $ring_radius); my $slope_angle2 = sin(($hip_width / 2) / $radius2); $wx1 = $x1 + ($radius * cos($angle + $slope_angle)); $wy1 = $y1 + ($radius * sin($angle + $slope_angle)); $wx2 = $x1 + ($radius * cos($angle + $theta - $slope_angle)); $wy2 = $y1 + ($radius * sin($angle + $theta - $slope_angle)); $wx3 = $x1 + ($radius2 * cos($angle + $theta - $slope_angle2)); $wy3 = $y1 + ($radius2 * sin($angle + $theta - $slope_angle2)); $wx4 = $x1 + ($radius2 * cos($angle + $slope_angle2)); $wy4 = $y1 + ($radius2 * sin($angle + $slope_angle2)); $str = sprintf("POLYLINE\n5\n%dB\n8\n%d\n66\n%d\n10\n0.0\n20\n0.0\n30\n0.0\n70\n1\n0\n", $poly_line_count,$DXF_LAYER,$DFX_LINE_TYPE); print FILE $str; $poly_line_count++; $str = sprintf("VERTEX\n5\n%dB\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx1,$wy1); print FILE $str; $str = sprintf("VERTEX\n5\n%dC\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx2,$wy2); print FILE $str; $str = sprintf("VERTEX\n5\n%dD\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx3,$wy3); print FILE $str; $str = sprintf("VERTEX\n5\n%dE\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx4,$wy4); print FILE $str; $str = sprintf("SEQEND\n5\n%dFF\n8\n0\n0\n", $poly_line_count); print FILE $str; } #=============================================================================# sub dxf_hip_point_rect{ my ($angle,$x1,$y1,$width,$height) = @_; $poly_line_count++; $diag = hypot($height/2,$height/2); $diag_radius = hypot($diag+($height/2),$height/2); $a = atan($height/2 / ($diag+($height/2))); $b = atan(($diag + ($height/2)) / ($height/2)); $wx1 = $x1 + ($diag * cos($angle)); $wy1 = $y1 + ($diag * sin($angle)); $wx2 = $x1 + ($diag_radius * cos($angle - $a)); $wy2 = $y1 + ($diag_radius * sin($angle - $a)); $wx3 = $x1 + ($width * cos($angle)) + (($height/2) * sin($angle)); $wy3 = $y1 + ($width * sin($angle)) - (($height/2) * cos($angle)); $wx4 = $x1 + ($width * cos($angle)) - (($height/2) * sin($angle)); $wy4 = $y1 + ($width * sin($angle)) + (($height/2) * cos($angle)); $wx5 = $x1 + ($diag_radius * cos($angle + $a)); $wy5 = $y1 + ($diag_radius * sin($angle + $a)); $str = sprintf("POLYLINE\n5\n%dB\n8\n%d\n66\n%d\n10\n0.0\n20\n0.0\n30\n0.0\n70\n1\n0\n", $poly_line_count,$DXF_LAYER,$DFX_LINE_TYPE); print FILE $str; $poly_line_count++; $str = sprintf("VERTEX\n5\n%dB\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx1,$wy1); print FILE $str; $str = sprintf("VERTEX\n5\n%dC\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx2,$wy2); print FILE $str; $str = sprintf("VERTEX\n5\n%dD\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx3,$wy3); print FILE $str; $str = sprintf("VERTEX\n5\n%dE\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx4,$wy4); print FILE $str; $str = sprintf("VERTEX\n5\n%dF\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx5,$wy5); print FILE $str; $str = sprintf("SEQEND\n5\n%dFF\n8\n0\n0\n", $poly_line_count); print FILE $str; } #=============================================================================# sub dxf_hip_rect{ my ($angle,$x1,$y1,$width,$height) = @_; $poly_line_count++; $wx1 = $x1 + (($height/2) * sin($angle)); $wy1 = $y1 - (($height/2) * cos($angle)); #print "\n\n angle = " .($angle * $RAD_TO_DEGREE); $wx2 = $x1 + ($width * cos($angle)) + (($height/2) * sin($angle)); $wy2 = $y1 + ($width * sin($angle)) - (($height/2) * cos($angle)); $wx3 = $x1 + ($width * cos($angle)) - (($height/2) * sin($angle)); $wy3 = $y1 + ($width * sin($angle)) + (($height/2) * cos($angle)); $wx4 = $x1 - (($height/2) * sin($angle)); $wy4 = $y1 + (($height/2) * cos($angle)); $str = sprintf("POLYLINE\n5\n%dB\n8\n%d\n66\n%d\n10\n0.0\n20\n0.0\n30\n0.0\n70\n1\n0\n", $poly_line_count,$DXF_LAYER,$DFX_LINE_TYPE); print FILE $str; $poly_line_count++; $str = sprintf("VERTEX\n5\n%dB\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx1,$wy1); print FILE $str; $str = sprintf("VERTEX\n5\n%dC\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx2,$wy2); print FILE $str; $str = sprintf("VERTEX\n5\n%dD\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx3,$wy3); print FILE $str; $str = sprintf("VERTEX\n5\n%dE\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$wx4,$wy4); print FILE $str; $str = sprintf("SEQEND\n5\n%dF\n8\n0\n0\n", $poly_line_count); print FILE $str; } #=============================================================================# sub dxf_rect{ my ($x1,$y1,$width,$height) = @_; $poly_line_count++; $str = sprintf("POLYLINE\n5\n%dB\n8\n%d\n66\n%d\n10\n0.0\n20\n0.0\n30\n0.0\n70\n1\n0\n", $poly_line_count,$DXF_LAYER,$DFX_LINE_TYPE); print FILE $str; $poly_line_count++; $str = sprintf("VERTEX\n5\n%dB\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$x1,$y1); print FILE $str; $str = sprintf("VERTEX\n5\n%dC\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$x1+$width,$y1); print FILE $str; $str = sprintf("VERTEX\n5\n%dD\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$x1+$width,$y1+$height); print FILE $str; $str = sprintf("VERTEX\n5\n%dE\n8\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n0\n", $poly_line_count,$DFX_LINE_TYPE,$x1,$y1+$height); print FILE $str; $str = sprintf("SEQEND\n5\n%dF\n8\n0\n0\n", $poly_line_count); print FILE $str; } #=============================================================================# sub dxf_line { my ($x1,$y1,$x2,$y2) = @_; $color=0; $dxf_line_count++; $str = sprintf("LINE\n5\n%dD\n8\n%d\n6\nCONTINOUS\n62\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n11\n%lf\n21\n%lf\n31\n0.0\n0\n", $dxf_line_count,$DXF_LAYER,$DFX_COLOR,$x1,$y1,$x2,$y2); #print $str; print FILE $str; } #=============================================================================# sub dxf_arc { my ($x1,$y1,$radius) = @_; $start=0.0000; $end=180.0000; $arc_count++; $str = sprintf("0\nARC\n5\n26\n8\n0\n62\n%d\n10\n%lf\n20\n%lf\n30\n0\n40\n%lf\n50\n%lf\n51\n%lf\n", $DFX_COLOR,$x1,$y1,$radius,$start,$end); $str = sprintf("ARC\n5\n8B\n8\n0\n62\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n40\n%lf\n50\n%lf\n51\n%lf\n0\n", $DFX_COLOR,$x1,$y1,$radius,$start,$end); $str = sprintf("ARC\n8\n0\n62\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n40\n%lf\n50\n%lf\n51\n%lf\n0\n", $DFX_COLOR,$x1,$y1,$radius,$start,$end); $str = sprintf("ARC\n5\n%dA\n8\n0\n62\n%d\n10\n%lf\n20\n%lf\n30\n0.0\n40\n%lf\n50\n%lf\n51\n%lf\n0\n", $arc_count,$DFX_COLOR,$x1,$y1,$radius,$start,$end); print FILE $str; } #=============================================================================# sub dxf_circle{ my ($x1,$y1,$radius) = @_; $dxf_circle_count++; $str = sprintf("CIRCLE\n5\n10B%d\n8\n0\n10\n%lf\n20\n%lf\n30\n0\n40\n%lf\n0\n", $dxf_circle_count,$x1,$y1,$radius); print FILE $str; } #=============================================================================# sub escape_string { my($esc) = @_; $esc =~ s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; $esc =~ s/ /+/g; return $esc; } #=============================================================================# sub get_dxf_header_file{ my($file)=shift; my $header; open(FH, "<$file") || die("$file: Can't open because ($!)."); while(){ $header .= $_; } close(FH); return $header; } #=============================================================================# sub hypot{ my ($x,$y) = @_; my $s = sqrt( $x* $x + $y * $y); return $s; } #=============================================================================# sub convertTOfeet{ my ($decimal) = @_; return $decimal unless $show_feet_inches eq 'yes'; #print "\n inches decimal = " .$decimal; my $wholefeet = floor($decimal/12); my $wholeinch = floor($decimal - ($wholefeet*12)); my $decimalfrac = ($decimal*1) - floor($decimal); my ($frac1,$frac2,$frac_str); $frac2 = 16; if ($decimalfrac >= 0.9774) # 15/16 = 0.9375 { $wholeinch++; $decimalfrac = 0.00; if($wholeinch == 12) { $wholefeet++; $wholeinch = 0; } } if ($decimalfrac > 0.0001) { $frac1 = $decimalfrac * $frac2; my $wholefrac = floor($decimalfrac * $frac2); $frac1 = ceil($decimalfrac * $frac2); $frac1 = 15 if($frac1 == 16); ($frac1,$frac2) = check_frac($frac1,$frac2); $frac_str = sprintf(" %d/%d",$frac1,$frac2); } my $str = sprintf("%d'-%d%s''", $wholefeet,$wholeinch,$frac_str); return $str; } #=============================================================================# sub check_frac{ my ($numerator ,$denominator) = @_; return (7,8) if $numerator eq 14; return (3,4) if $numerator eq 12; return (5,8) if $numerator eq 10; return (1,2) if $numerator eq 8; return (3,8) if $numerator eq 6; return (1,4) if $numerator eq 4; return (1,8) if $numerator eq 2; return ("","") if $numerator eq 0; return ("","") if $denominator eq 0; return ($numerator ,$denominator); } #=============================================================================# sub roundAngle{ my ($angle) = @_; my $str = sprintf("%.2f",$angle); return $str; } #===================================================================# sub read_input { my($buffer) = undef; my ($item); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); } else { $buffer=$ENV{'QUERY_STRING'}; } $buffer = $ARGV[0] if (not $buffer); my @pairs=split(/&/,$buffer); foreach $item(@pairs) { my ($key,$content)=split (/=/,$item,2); # Split into key and value. $content =~ tr/+/ /; # Convert plus's to spaces $content =~ s/%(..)/pack("c",hex($1))/ge; # Convert %XX from hex numbers to alphanumeric $content =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # prevent hackers from exploiting the input name $key =~ tr/+/ /; # Convert plus's to spaces $key =~ s/%(..)/pack("c",hex($1))/ge; # Convert %XX from hex numbers to alphanumeric $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $key =~ s/ /_/g; # get rid of attempts to insert HTML tags $content =~ s///g; # server-side-includes $content =~ s/<([^>]|\n)*>//gs; $content =~ s//>/g; # get rid of attempts to insert illegal characters $content =~ s/\\//g; # remove black slashes $content =~ s/\0//g; # remove nulls $content =~ s/[\\\&\;\`\'\"\|\*\?\~\^\[\]\{\}\$]//gs; $content =~ s/\cM/\n/g; #convert CR to LF $content =~ s/^\s+|\s+$//gs; $content = substr($content,0,4096); $data{$key} = $content; } return 1; }