#!/usr/local/bin/perl # perl script for Equal Pitch Bay Window Rafter Calculations # type 6: referred to as Equal Pitch Baywindow # type 1 WestBuild Baywindow # type 2 JoeCarlo Baywindow # type 3 EastBuild Baywindow # type 4 JoeCarlo Unequal Pitch Baywindow # type 5 Bay To Point Baywindow # type 6 Equal Pitch Baywindow use CGI::Carp qw(fatalsToBrowser); #comment out this line when your done debugging this script $|++; #dont't buffer output #use strict; # file name:: baywindow.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 What is a Polygon? A closed plane figure made up of several line segments that are joined together. The sides do not cross each other. Exactly two sides meet at every vertex. This bay window rafter script is based on the straight skeleton of a polygon with the bay hip rafter bisecting the bay window corner vertices. more info at this url for straight skeleton of a polygon http://www.vterrain.org/Culture/BldCity/Roof/ =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{'back_wall'} eq ""){ # hand edit baywindow variables below for default values $back_wall = 120; $projection = 24; $face_wall = 72; $pitch = 8; $show_feet_inches = 'no'; $jack_spacing = 12; $overhang = 12; } else{ $back_wall = $data{'back_wall'}; $projection = $data{'projection'}; $face_wall = $data{'face_wall'}; $pitch = $data{'pitch'}; $show_feet_inches = $data{'show_feet_inches'}; $jack_spacing = $data{'jack_spacing'}; $overhang = $data{'overhang'}; } #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_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 $half_the_thickness_of_the_hips = 0.75; # back wall length must be > or = face wall length $back_wall = $face_wall if($back_wall < $face_wall); $face_wall_half = $face_wall / 2; if($back_wall > $face_wall) { $projection_offset = ($back_wall - $face_wall) /2; } else { $projection_offset = 0;} # get geometry angles for baywindow $run = $projection; $common_rafter_run = $run; $common_rafter_run_to_fascia = $run + $overhang; if($projection_offset > 0){ $projection_wall_angle_deg = $RAD_TO_DEGREE * atan($projection / $projection_offset); } else { $projection_wall_angle_deg = 90; } $projection_offset_wall_angle_deg = 90 - $projection_wall_angle_deg; $interior_wall_angle_deg = 90 + $projection_offset_wall_angle_deg; $bay_hip_rafter_run_bisect_angle_deg = $interior_wall_angle_deg / 2; $bay_hip_rafter_top_angle_deg = 90 - $bay_hip_rafter_run_bisect_angle_deg; $bay_hip_rafter_run_bisect_adj_angle_deg = $interior_wall_angle_deg - $bay_hip_rafter_run_bisect_angle_deg; $bay_hip_rafter_run_bisect_adj_top_angle_deg = 90 - $bay_hip_rafter_run_bisect_adj_angle_deg; $theta = $DEGREE_TO_RAD * $bay_hip_rafter_run_bisect_angle_deg; $bay_hip_rafter_run_offset = $projection / tan($theta); $wall_hip_rafter_run = $projection_offset + $bay_hip_rafter_run_offset; $pitch_angle = $RAD_TO_DEGREE * atan($pitch / 12); $Major_Pitch = atan($pitch / 12); $Minor_Pitch = atan($pitch / 12); $common_rafter_rise = $run * ($pitch / 12); $common_rafter_length = $run / cos(atan($pitch / 12)); $overhang_rafter_length = $overhang / cos(atan($pitch / 12)); $common_rafter_length_to_fascia = $common_rafter_run_to_fascia / cos(atan($pitch / 12)); $bay_hip_rafter_run = $run / sin($theta); $bay_hip_rafter_angle = atan($common_rafter_rise / $bay_hip_rafter_run); $bay_hip_rafter_pitch = (tan($bay_hip_rafter_angle) ) * 12; $bay_hip_rafter_unit_run = (12 / sin($theta)); $bay_hip_rafter_unit_run_hypot = (12 / sin($theta)) / cos($bay_hip_rafter_angle); $bay_hip_rafter_length = $bay_hip_rafter_run / cos($bay_hip_rafter_angle); $bay_hip_rafter_bevel_angle = $bay_hip_rafter_top_angle_deg; $overhang_bay_hip_run = $overhang / cos($bay_hip_rafter_top_angle_deg * $DEGREE_TO_RAD); $overhang_bay_hip_length = $overhang_bay_hip_run / cos($bay_hip_rafter_angle); $bay_hip_rafter_run_to_fascia = $common_rafter_run_to_fascia / sin($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $bay_hip_rafter_length_to_fascia = $bay_hip_rafter_run_to_fascia / cos($bay_hip_rafter_angle); $wall_common_jackrafter_run = $jack_spacing * tan($projection_wall_angle_deg * $DEGREE_TO_RAD); $wall_common_jackrafter_length = $wall_common_jackrafter_run / cos(atan($pitch / 12)); $wall_hip_rafter_run = $projection_offset + $bay_hip_rafter_run_offset; $wall_hip_rafter_angle = atan($common_rafter_rise / $wall_hip_rafter_run); $hip_square = hypot(12,12); $wall_hip_rafter_pitch = tan($wall_hip_rafter_angle) * $hip_square; $wall_hip_rafter_length = $wall_hip_rafter_run / cos($wall_hip_rafter_angle); $wall_hip_rafter_bevel_angle = $projection_wall_angle_deg; $wall_hip_rafter_unit_run = (12 / sin($projection_wall_angle_deg * $DEGREE_TO_RAD)); $common_rafter_run_to_fascia = ($common_rafter_run + $overhang); $common_rafter_rise_from_fascia = ($common_rafter_run + $overhang) * ($pitch / 12); $exterior_angle_deg = $DEGREE_TO_RAD * (360 - $interior_wall_angle_deg); $zero_tail = $overhang / cos($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $overhang_wall_hip = $zero_tail / cos($wall_hip_rafter_angle); if($projection_offset > 0){ $projection_wall_length = $projection_offset / cos($projection_wall_angle_deg * $DEGREE_TO_RAD); } else{$projection_wall_length = $projection;} print "Equal Pitch Bay Window Rafter Calculations\nType 6: Equal Pitch Baywindow"; print "\nCalculations are rounded to the nearest 1/16 inch"; print "\n\n Back Wall Length = " .convertTOfeet($back_wall); print "\n\n Face Wall length = " .convertTOfeet($face_wall); print "\n\n Projection of Bay Window = " .convertTOfeet($projection); print "\n\n Projection Offset = " .convertTOfeet($projection_offset); print "\n\n Projection Wall Length = " .convertTOfeet($projection_wall_length); print "\n\n Projection Wall Angle = " .roundAngle($projection_wall_angle_deg); print "\n\n Projection Offset Wall Angle = " .roundAngle($projection_offset_wall_angle_deg); print "\n\n Interior Wall Angle = " .roundAngle($interior_wall_angle_deg); print "\n\n Bay Hip Rafter Run Bisect Angle = " .roundAngle($bay_hip_rafter_run_bisect_angle_deg); print "\n\n\n Common Rafter Run = " .convertTOfeet($projection); print "\n\n Common Rafter Pitch Angle = " .roundAngle($pitch_angle); print "\n\n Common Rafter Pitch = " .roundAngle($pitch); 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 Length To Fascia = " .convertTOfeet($common_rafter_length_to_fascia); print "\n\n Common Rafter Run To Fascia = " .convertTOfeet($common_rafter_run_to_fascia); print "\n\n Common Rafter Overhang Run = " .convertTOfeet($overhang); print "\n\n Common Overhang Rafter Length = " .convertTOfeet($overhang_rafter_length); print "\n\n 45 Wall Jack Rafter Spacing = " .convertTOfeet($jack_spacing); print "\n\n 45 Wall Jack Rafter Difference in Length = " .convertTOfeet($wall_common_jackrafter_length); print "\n\n\n Bay Hip Rafter Angle = " .roundAngle($bay_hip_rafter_angle * $RAD_TO_DEGREE); print "\n\n Bay Hip Rafter Pitch = " .convertTOpitch($bay_hip_rafter_pitch) ." /12"; print "\n\n Bay Hip Rafter Bevel Angle = " .roundAngle($bay_hip_rafter_bevel_angle); print "\n\n Bay Hip Rafter Run = " .convertTOfeet($bay_hip_rafter_run); print "\n\n Bay Hip Rafter Unit Run = " .roundAngle($bay_hip_rafter_unit_run); print "\n\n Bay Hip Rafter Length = " .convertTOfeet($bay_hip_rafter_length); print "\n\n Bay Hip Rafter Run To Fascia = " .convertTOfeet($bay_hip_rafter_run_to_fascia ); print "\n\n Bay Hip Rafter Length To Fascia = " .convertTOfeet($bay_hip_rafter_length_to_fascia ); print "\n\n Bay Hip Rafter Overhang Run = " .convertTOfeet($overhang_bay_hip_run); print "\n\n Bay Hip Rafter Overhang Rafter Length = " .convertTOfeet($overhang_bay_hip_length); print "\n\n\n Wall Hip Rafter Angle = " .roundAngle($wall_hip_rafter_angle * $RAD_TO_DEGREE); print "\n\n Wall Hip Rafter Pitch = " .convertTOpitch($wall_hip_rafter_pitch) ." /" .roundAngle($hip_square); print "\n\n Wall Hip Rafter Run = " .convertTOfeet($wall_hip_rafter_run); print "\n\n Wall Hip Rafter Unit Run = " .roundAngle($wall_hip_rafter_unit_run); print "\n\n Wall Hip Rafter Length = " .convertTOfeet($wall_hip_rafter_length); print "\n\n Wall Hip Rafter Bevel Angle = " .roundAngle($wall_hip_rafter_bevel_angle); print "\n\n Wall Hip Rafter Overhang Run = " .convertTOfeet($overhang); print "\n\n Wall Hip Rafter Overhang Diagonal Rafter Length At 45 Wall = " .convertTOfeet($overhang_wall_hip); $Major_Side_Plan_Angle = abs(atan (sin $exterior_angle_deg / ($Major_Pitch / $Minor_Pitch + cos $exterior_angle_deg))); if($projection_offset > 0){$Major_Side_Plan_Angle = $bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD;} # works for 90° walls only # $Frieze_Block_Angle = atan(cos((90.00 - ($Major_Pitch* $RAD_TO_DEGREE))* $DEGREE_TO_RAD)); $Frieze_Block_Angle = atan (sin ($Major_Pitch) / tan($Major_Side_Plan_Angle)); $Frieze_Block_Bevel_Angle = atan (sin ($Frieze_Block_Angle) / tan ($Major_Pitch)); print "\n\n Bay Hip Plan Angle = " .roundAngle($Major_Side_Plan_Angle * $RAD_TO_DEGREE); print "\n\n Frieze Block Angle = " .roundAngle($Frieze_Block_Angle * $RAD_TO_DEGREE); print "\n\n Frieze Block Bevel Angle = " .roundAngle($Frieze_Block_Bevel_Angle * $RAD_TO_DEGREE); $Backing_Angle = acos (cos($pitch_angle * $DEGREE_TO_RAD) / cos ($bay_hip_rafter_angle)); print "\n\n Bay Hip Rafter Backing Angle = " .roundAngle($Backing_Angle * $RAD_TO_DEGREE); $bay_hip_rafter_drop = ($pitch * ($half_the_thickness_of_the_hips / tan($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD))/$bay_hip_rafter_unit_run); print "\n\n Bay Hip Rafter Drop = " .convertTOfeet($bay_hip_rafter_drop); # if the $projection_wall_angle_deg == 45 then sin of 45 = 1 and Wall Hip Rafter Drop = half_the_thickness_of_the_hips * pitch/16.97 or * tan(hip_angle) $wall_hip_rafter_drop = ($pitch * ($half_the_thickness_of_the_hips / tan($projection_wall_angle_deg * $DEGREE_TO_RAD))/$wall_hip_rafter_unit_run); print "\n\n Wall Hip Rafter Drop = " .convertTOfeet($wall_hip_rafter_drop); # origin of left top side of baywindow in dxf document $originX = 25; $originY = 100; # text file to save dxf drawing to $DXF_File="baywindow.dxf"; # text file with dxf header information $DXF_HEADER_FILE = "dxf_header.txt"; #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"; $offset = $overhang * tan($bay_hip_rafter_top_angle_deg * $DEGREE_TO_RAD); $offset_45 = $overhang * tan($bay_hip_rafter_run_bisect_adj_top_angle_deg * $DEGREE_TO_RAD); $offset_fascia = $overhang / cos($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $offset_zero_fascia_x = $overhang * cos($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $offset_zero_fascia_y = $overhang * sin($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); # draw back wall $x1 = $originX; $y1 = $originY; $x2 = $originX + $back_wall; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw projection wall left $x1 = $originX; $y1 = $originY; $x2 = $originX + $projection_offset; $y2 = $originY - $projection; dxf_line($x1,$y1,$x2,$y2); # draw face wall $x1 = $originX + $projection_offset; $y1 = $originY - $projection; $x2 = $originX + $back_wall - $projection_offset; $y2 = $originY - $projection; dxf_line($x1,$y1,$x2,$y2); # draw projection wall right $x1 = $originX + $back_wall - $projection_offset; $y1 = $originY - $projection; $x2 = $originX + $back_wall; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw back wall left hip rafter $x1 = $originX + $wall_hip_rafter_run; $y1 = $originY; $x2 = $originX - $offset_fascia; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw back wall right hip rafter $x1 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run; $y1 = $originY; $x2 = $originX + $projection_offset + $face_wall + $projection_offset + $offset_fascia; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw left face wall bay hip run to fascia $x1 = $originX + $wall_hip_rafter_run; $y1 = $originY; $x2 = $originX + $projection_offset - $offset; $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw right face wall bay hip run to fascia $x1 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run; $y1 = $originY; $x2 = $originX + $projection_offset + $face_wall + $offset; $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw face wall fascia line $x1 = $originX + $projection_offset - $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $projection_offset + $face_wall + $offset; $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw left fascia line at 45 wall $x1 = $originX + $projection_offset - $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX - $offset_fascia; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw right fascia line at 45 wall $x1 = $originX + $projection_offset + $face_wall + $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $projection_offset + $face_wall + $projection_offset + $offset_fascia; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw back wall zero tail left rafter $x1 = $originX; $y1 = $originY; $x2 = $originX - $offset_zero_fascia_x; $y2 = $originY - $offset_zero_fascia_y; dxf_line($x1,$y1,$x2,$y2); # draw back wall zero tail right rafter $x1 = $originX + $projection_offset + $face_wall + $projection_offset; $y1 = $originY; $x2 = $originX + $projection_offset + $face_wall + $projection_offset + $offset_zero_fascia_x; $y2 = $originY - $offset_zero_fascia_y; dxf_line($x1,$y1,$x2,$y2); # draw common rafters on face wall if($face_wall_half >= $jack_spacing){ $max = ceil(($face_wall_half - $bay_hip_rafter_run_offset) / $jack_spacing); for($i=0; $i< $max; $i++){ # draw face wall left common rafter $x1 = $originX + $wall_hip_rafter_run + ($jack_spacing * $i); $y1 = $originY; $x2 = $originX + $wall_hip_rafter_run + ($jack_spacing * $i); $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw face wall right common rafter $x1 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run - ($jack_spacing * $i); $y1 = $originY; $x2 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run - ($jack_spacing * $i); $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); } } if($projection_wall_angle_deg != 90){ $theta = $DEGREE_TO_RAD * $projection_wall_angle_deg; $y0 =0; $x0 = $bay_hip_rafter_run_offset * cos($theta); } else{ $x0 = 0; $theta = $PIE / 2;} $y0 = $bay_hip_rafter_run_offset * sin($theta); if($projection_wall_angle_deg != 90){ $wall_45_king_common_total_run = ($bay_hip_rafter_run_to_fascia) * cos($bay_hip_rafter_run_bisect_adj_top_angle_deg * $DEGREE_TO_RAD); $px1 = $wall_45_king_common_total_run * cos($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $py1 = $wall_45_king_common_total_run * sin($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $fx1 = $originX + $wall_hip_rafter_run - $px1; $fy1 = $originY - $projection + $run - $py1; $sfx1 = $fx1; $sfy1 = $fy1; $sfx2 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run + $px1; $sfy2 = $originY - $projection + $run - $py1; # draw left 45 wall king common $x1 = $originX + $wall_hip_rafter_run; $y1 = $originY; $x2 = $fx1; $y2 = $fy1; dxf_line($x1,$y1,$x2,$y2); # draw right 45 wall king common $x1 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run; $y1 = $originY; $x2 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run + $px1; $y2 = $fy1; $sfx2 = $x2; $sfy2 = $y2; dxf_line($x1,$y1,$x2,$y2); $max = floor(($projection_wall_length - $bay_hip_rafter_run_offset ) / $jack_spacing); for($i=1; $i<= $max; $i++){ # back side jackrafters $t_length = ($jack_spacing * $i) / sin($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $jack_offset = ($projection_wall_length - $bay_hip_rafter_run_offset - ($jack_spacing * $i)) / tan($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); $common_jackrafter_length = $jack_offset / cos($Minor_Pitch); print "\n\n 45 Wall Back Common Jack Rafter # $i = " .convertTOfeet($common_jackrafter_length); $pxx1 = $t_length; # point at hip $pyy1 = 0; # point at hip $px1 = ($jack_spacing * $i) * sin($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); # point at fascia line $py1 = ($jack_spacing * $i) * cos($projection_offset_wall_angle_deg * $DEGREE_TO_RAD); # point at fascia line $x1 = $originX + $wall_hip_rafter_run - $pxx1; # point at hip $y1 = $originY - $pyy1; # point at hip $x2 = $sfx1 - $px1; # point at fascia line $y2 = $sfy1 + $py1; # point at fascia line dxf_line($x1,$y1,$x2,$y2); # back side left $x1 = $originX + $projection_offset + $face_wall + $projection_offset - $wall_hip_rafter_run + $pxx1; # point at hip $y1 = $originY - $pyy1; # point at hip $x2 = $sfx2 + $px1; # point at fascia line $y2 = $sfy2 + $py1; # point at fascia line dxf_line($x1,$y1,$x2,$y2); # back side right } } $str= "ENDSEC\n0\nEOF"; print FILE $str; close FILE; exit; ################################### # library sub routines follow ################################### # [Ctrl]+E for zoom extents 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 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 convertTOpitch{ my ($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%s", $wholeinch,$frac_str); 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; }