#!/usr/local/bin/perl # perl script for Offset Hips on Bay Window Rafter Calculations # type 2: referred to as Joe Carola Baywindow # type 1 WestBuild Baywindow # type 2 Joe Carola Baywindow # type 3 EastBuild Baywindow # type 4 Joe Carola Unequal Pitch Baywindow # type 5 Joe Carola 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:: joe-carlo-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 ################################################### 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{'face_wall'} eq ""){ # hand edit baywindow variables below for default values $projection = 24; $face_wall = 72; $pitch = 8; $show_feet_inches = 'no'; $jack_spacing = 12; $overhang = 12; } else{ $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'}; } # walls at 45 degree angles to face wall $projection_offset = $projection; #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; # get geometry angles for baywindow $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; $face_wall_half = $face_wall /2; # calculate total span for Octagon Baywindow # span = side wall projection * 2 + face wall length $bay_hip_rafter_offset_at_fascia = $overhang / tan(67.5 * $DEGREE_TO_RAD); $fascia_face_wall_half = $bay_hip_rafter_offset_at_fascia + $face_wall_half; $span = ($projection * 2) + $face_wall; $common_rafter_run = $span / 2; $run = $common_rafter_run; # calculate hip offsets from fascia overhang for Baywindow # To calculate the wall bay hip rafter run bisect angle we can use the hypotenuse of a right triangle: # wall bay hip rafter run = hypot( common run , common run - projection ) # wall bay hip rafter run bisect angle = 135° - arctan ( common run ÷ (common run - projection) ) # To calculate the 45° wall common rafter angle we can use the hypotenuse of a right triangle: # 45° wall common rafter run to fascia = overhang + (sin ( wall bay hip rafter run bisect angle ) * wall bay hip rafter run ) # 45° wall common rafter angle = arctan ( common rafter rise from fascia ÷ 45° wall king common run to fascia ) $common_rafter_run_to_fascia = ($common_rafter_run + $overhang); $bay_hip_rafter_run_bisect_angle_deg = $RAD_TO_DEGREE * atan($common_rafter_run_to_fascia / ($face_wall_half + $bay_hip_rafter_offset_at_fascia)); $bay_hip_rafter_top_angle_deg = 90 - $bay_hip_rafter_run_bisect_angle_deg; $bay_hip_rafter_run_to_fascia = $common_rafter_run_to_fascia / sin($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $overhang_bay_hip_run = $overhang / cos($bay_hip_rafter_top_angle_deg * $DEGREE_TO_RAD); $bay_hip_rafter_run = $bay_hip_rafter_run_to_fascia - $overhang_bay_hip_run; $bay_hip_rafter_offset_at_face_wall_corner = $face_wall_half - ($common_rafter_run / tan($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD)); $bay_hip_rafter_run_bisect_adj_angle_deg = 135 - $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; $pitch_angle = $RAD_TO_DEGREE * atan($pitch / 12); $Major_Pitch = atan($pitch / 12); $common_rafter_rise = $run * ($pitch / 12); $common_rafter_length = $run / cos(atan($pitch / 12)); $common_jackrafter_run = $jack_spacing * tan($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $common_jackrafter_length = $common_jackrafter_run / cos(atan($pitch / 12)); $overhang_face_wall_length = $overhang / cos(atan($pitch / 12)); $valley_square = hypot(12,12); $valley_rafter_run = hypot($run,$run); $valley_rafter_angle = atan($common_rafter_rise / $valley_rafter_run); $valley_rafter_pitch = (tan($valley_rafter_angle) ) * $valley_square; $valley_rafter_length = $run / cos($valley_rafter_angle); $bay_hip_rafter_angle = atan($common_rafter_rise / $bay_hip_rafter_run); $bay_hip_rafter_length = $bay_hip_rafter_run / cos($bay_hip_rafter_angle); $bay_hip_rafter_bevel_angle = 90 - $bay_hip_rafter_run_bisect_angle_deg; $bay_hip_rafter_unit_run = (12 / sin($DEGREE_TO_RAD * $bay_hip_rafter_run_bisect_angle_deg)); $bay_hip_rafter_pitch = (tan($bay_hip_rafter_angle) ) * 12; $overhang_bay_hip_length = $overhang_bay_hip_run / cos($bay_hip_rafter_angle); $bay_hip_rafter_length_to_fascia = $bay_hip_rafter_run_to_fascia / cos($bay_hip_rafter_angle); $wall_common_rafter_run_to_fascia = $bay_hip_rafter_run_to_fascia * sin($bay_hip_rafter_run_bisect_adj_angle_deg * $DEGREE_TO_RAD); $wall_common_rafter_run = $wall_common_rafter_run_to_fascia - $overhang; $wall_common_rafter_angle = atan($common_rafter_rise / $wall_common_rafter_run); $wall_common_rafter_pitch = (tan($wall_common_rafter_angle) ) * 12; $Minor_Pitch = $wall_common_rafter_angle; $wall_common_rafter_length = $wall_common_rafter_run / cos($wall_common_rafter_angle); $wall_common_rafter_length_to_fascia = $wall_common_rafter_run_to_fascia / cos($wall_common_rafter_angle); $wall_common_jackrafter_run = $jack_spacing * tan($bay_hip_rafter_run_bisect_adj_angle_deg * $DEGREE_TO_RAD); $wall_common_jackrafter_length = $wall_common_jackrafter_run / cos($wall_common_rafter_angle); # bay hip at inside corner of baywindow $wall_bay_hip_rafter_run = hypot($common_rafter_run,$common_rafter_run - $projection); $wall_bay_hip_rafter_run_bisect_angle_deg = $RAD_TO_DEGREE * atan($wall_common_rafter_run / $half_projection_wall_length); $wall_bay_hip_rafter_run_top_angle_deg = 90 - $wall_bay_hip_rafter_run_bisect_angle_deg; $wall_bay_hip_rafter_angle = atan($common_rafter_rise / $wall_bay_hip_rafter_run); $wall_bay_hip_rafter_length = $wall_bay_hip_rafter_run / cos($wall_bay_hip_rafter_angle); $wall_bay_hip_rafter_pitch = (tan($wall_bay_hip_rafter_angle) ) * 12; $overhang_run_45_wall = $overhang; # $overhang_bay_hip_run * cos($bay_hip_rafter_run_bisect_adj_top_angle_deg * $DEGREE_TO_RAD); $overhang_45_wall_length = $overhang_run_45_wall / cos($wall_common_rafter_angle); $rise_face_wall = $overhang * ($pitch / 12); $rise_45_wall = $overhang * tan($wall_common_rafter_angle); $wall_common_rafter_HAP = $rise_45_wall - $rise_face_wall; $wall_bay_hip_rafter_run_top_adj_angle_deg = 90 - ($wall_bay_hip_rafter_run_top_angle_deg + $bay_hip_rafter_run_bisect_adj_top_angle_deg + $bay_hip_rafter_top_angle_deg); $dog_leg_valley_rafter_run = $overhang / cos(22.5 * $DEGREE_TO_RAD); $overhang_rise = $overhang * ($pitch / 12); $dog_leg_valley_rafter_angle = atan($overhang_rise / $dog_leg_valley_rafter_run); $dog_leg_valley_rafter_pitch = (tan($dog_leg_valley_rafter_angle) ) * 12; $dog_leg_valley_rafter_length = $dog_leg_valley_rafter_run / cos($dog_leg_valley_rafter_angle); print "Offset Hips on Bay Window Rafter Calculations\nType 2: Joe Carola Baywindow"; print "\nCalculations are rounded to the nearest 1/16 inch"; 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 Bay Hip Rafter Run Adjacent Bisect Angle = " .roundAngle($bay_hip_rafter_run_bisect_adj_angle_deg); print "\n\n\n Common Rafter Run = " .convertTOfeet($run); print "\n\n Common Rafter Run To Fascia = " .convertTOfeet($common_rafter_run_to_fascia); 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_face_wall_length); print "\n\n Common Jack Rafter Spacing = " .convertTOfeet($jack_spacing); print "\n\n Common Jack Rafter Difference in Length = " .convertTOfeet($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 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 Bay Hip Rafter Offset At Fascia = " .convertTOfeet($bay_hip_rafter_offset_at_fascia); print "\n\n Bay Hip Rafter Offset At Face Wall Corner = " .convertTOfeet($bay_hip_rafter_offset_at_face_wall_corner); print "\n\n Bay Hip Rafter Run Top Bisect Angle = " .roundAngle($bay_hip_rafter_top_angle_deg); print "\n\n Bay Hip Rafter Run Top Adjacent Bisect Angle = " .roundAngle($bay_hip_rafter_run_bisect_adj_top_angle_deg); print "\n\n\n Wall Bay Hip Rafter Angle = " .roundAngle($wall_bay_hip_rafter_angle * $RAD_TO_DEGREE); print "\n\n Wall Bay Hip Rafter Pitch = " .convertTOpitch($wall_bay_hip_rafter_pitch) ." /12"; print "\n\n Wall Bay Hip Rafter Run = " .convertTOfeet($wall_bay_hip_rafter_run); print "\n\n Wall Bay Hip Rafter Length = " .convertTOfeet($wall_bay_hip_rafter_length); print "\n\n Wall Bay Hip Rafter Run Bisect Angle = " .roundAngle($wall_bay_hip_rafter_run_bisect_angle_deg); print "\n\n Wall Bay Hip Rafter Top Bisect Angle = " .roundAngle($wall_bay_hip_rafter_run_top_angle_deg); print "\n\n\n 45 Wall Common Rafter Angle = " .roundAngle($wall_common_rafter_angle * $RAD_TO_DEGREE); print "\n\n 45 Wall Rafter Pitch = " .convertTOpitch($wall_common_rafter_pitch) ." /12"; print "\n\n 45 Wall Common Rafter Run = " .convertTOfeet($wall_common_rafter_run); print "\n\n 45 Wall Common Rafter Length = " .convertTOfeet($wall_common_rafter_length); print "\n\n 45 Wall Common Rafter Run To Fascia = " .convertTOfeet($wall_common_rafter_run_to_fascia); print "\n\n 45 Wall Common Rafter Length To Fascia = " .convertTOfeet($wall_common_rafter_length_to_fascia); if($wall_common_jackrafter_length < $wall_common_rafter_length){ print "\n\n 45 Wall Jack Rafter Difference in Length = " .convertTOfeet($wall_common_jackrafter_length); } print "\n\n 45 Wall Common Rafter Overhang Run = " .convertTOfeet($overhang_run_45_wall); print "\n\n 45 Wall Common Rafter Overhang Rafter Length = " .convertTOfeet($overhang_45_wall_length); print "\n\n 45 Wall Common Rafter H.A.P Adjustment = " .convertTOfeet($wall_common_rafter_HAP); print "\n\n\n Valley Rafter Angle = " .roundAngle($valley_rafter_angle * $RAD_TO_DEGREE); print "\n\n Valley Rafter Pitch = " .convertTOpitch($valley_rafter_pitch) ." /" .roundAngle($valley_square); print "\n\n Valley Rafter Length = " .convertTOfeet($valley_rafter_length); print "\n\n\n Dog Leg Valley Rafter Angle = " .roundAngle($dog_leg_valley_rafter_angle * $RAD_TO_DEGREE); print "\n\n Dog Leg Valley Rafter Pitch = " .convertTOpitch($dog_leg_valley_rafter_pitch) ." /12"; print "\n\n Dog Leg Valley Rafter Length = " .convertTOfeet($dog_leg_valley_rafter_length); print "\n\n Dog Leg Valley Rafter Run = " .convertTOfeet($dog_leg_valley_rafter_run); $Major_Side_Plan_Angle = $bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD; $Minor_Side_Plan_Angle = $bay_hip_rafter_run_bisect_adj_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 Face Wall Frieze Block Angle = " .roundAngle($Frieze_Block_Angle * $RAD_TO_DEGREE); print "\n\n Face Wall 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); # 45 wall block angles $Minor_Pitch = $wall_common_rafter_angle; $Minor_Side_Plan_Angle = $bay_hip_rafter_run_bisect_adj_angle_deg * $DEGREE_TO_RAD; $Frieze_Block_Angle = atan (sin ($Minor_Pitch) / tan($Minor_Side_Plan_Angle)); $Frieze_Block_Bevel_Angle = atan (sin ($Frieze_Block_Angle) / tan ($Minor_Pitch)); print "\n\n 45 Wall Bay Hip Plan Angle = " .roundAngle($Minor_Side_Plan_Angle * $RAD_TO_DEGREE); print "\n\n 45 Wall Frieze Block Angle = " .roundAngle($Frieze_Block_Angle * $RAD_TO_DEGREE); print "\n\n 45 Wall Frieze Block Bevel Angle = " .roundAngle($Frieze_Block_Bevel_Angle * $RAD_TO_DEGREE); $Backing_Angle = acos (cos($Minor_Pitch ) / cos ($bay_hip_rafter_angle)); print "\n\n 45 Wall 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); print "\n\n Bay Hip Rafter At 45 Wall H.A.P Adjustment = " .convertTOfeet($wall_common_rafter_HAP); print "\n\n Valley H.A.P Adjustment At 45 Wall = " .convertTOfeet($wall_common_rafter_HAP); # Minor Plan Angle dog leg valley blocks $Frieze_Block_Angle = atan (sin ($dog_leg_valley_rafter_angle) / tan(67.5 * $DEGREE_TO_RAD)); $Frieze_Block_Bevel_Angle = atan (sin ($Frieze_Block_Angle) / tan ($dog_leg_valley_rafter_angle)); print "\n\n Dog Leg Valley Minor Plan Angle = " .roundAngle(67.5); print "\n\n Dog Leg Valley Minor Plan Angle Frieze Block Angle = " .roundAngle($Frieze_Block_Angle * $RAD_TO_DEGREE); print "\n\n Dog Leg Valley Minor Plan Angle Frieze Block Bevel Angle = " .roundAngle($Frieze_Block_Bevel_Angle * $RAD_TO_DEGREE); # text file with dxf header information $DXF_HEADER_FILE = "dxf_header.txt"; # text file to save dxf drawing to $DXF_File="joe-carlo-baywindow.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 of left top side of baywindow in dxf document $originX = 25; $originY = 100; #$offset = $overhang * tan($bay_hip_rafter_top_angle_deg * $DEGREE_TO_RAD); # keep the overhang the same run at each wall $offset = $overhang * tan(22.5 * $DEGREE_TO_RAD); $offset_45 = $overhang * tan($bay_hip_rafter_run_bisect_adj_top_angle_deg * $DEGREE_TO_RAD); # draw left 45 wall $x1 = $originX; $y1 = $originY; $x2 = $originX + $projection; $y2 = $originY - $projection; dxf_line($x1,$y1,$x2,$y2); # draw wall next to left 45 wall $x1 = $originX; $y1 = $originY; $x2 = $originX - $projection; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw face wall $x1 = $originX + $projection; $y1 = $originY - $projection; $x2 = $originX + $projection + $face_wall; $y2 = $originY - $projection; dxf_line($x1,$y1,$x2,$y2); # draw right 45 wall right $x1 = $originX + $projection + $face_wall; $y1 = $originY - $projection; $x2 = $originX + $projection + $face_wall + $projection; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw wall next to right 45 wall $x1 = $originX + $projection + $face_wall + $projection; $y1 = $originY; $x2 = $originX + $projection + $face_wall + $projection + $projection; $y2 = $originY; dxf_line($x1,$y1,$x2,$y2); # draw left face wall bay hip run to fascia $x1 = $originX + $projection - $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; dxf_line($x1,$y1,$x2,$y2); # draw right face wall bay hip run to fascia $x1 = $originX + $projection + $face_wall + $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; dxf_line($x1,$y1,$x2,$y2); # draw left wall bay hip run to fascia $x1 = $originX; $y1 = $originY; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; dxf_line($x1,$y1,$x2,$y2); # draw right wall bay hip run to fascia $x1 = $originX + $projection + $face_wall + $projection; $y1 = $originY; $x2 = $originX + $projection + $face_wall + $projection - $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; dxf_line($x1,$y1,$x2,$y2); # draw ridge $x1 = $originX + $common_rafter_run; $y1 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia + $projection; dxf_line($x1,$y1,$x2,$y2); # draw left valley $x1 = $originX; $y1 = $originY; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia + $projection; dxf_line($x1,$y1,$x2,$y2); # draw right valley $x1 = $originX + $projection + $face_wall + $projection; $y1 = $originY; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia + $projection; dxf_line($x1,$y1,$x2,$y2); # draw face wall fascia line $x1 = $originX + $projection - $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $projection + $face_wall + $offset; $y2 = $originY - $projection - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw left fascia line at 45 wall $x1 = $originX + $projection - $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX - $offset; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw left fascia line at 45 wall $x1 = $originX - $projection; $y1 = $originY - $overhang; $x2 = $originX - $offset; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw right fascia line at 45 wall $x1 = $originX + $projection + $face_wall + $offset; $y1 = $originY - $projection - $overhang; $x2 = $originX + $projection + $face_wall + $projection + $offset; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw right fascia line at 45 wall $x1 = $originX + $projection + $face_wall + $projection + $offset; $y1 = $originY - $overhang; $x2 = $originX + $projection + $face_wall + $projection + $projection; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw face wall king common $x1 = $originX + $common_rafter_run; $y1 = $originY - $projection - $overhang; $x2 = $originX + $common_rafter_run; $y2 = $originY - $projection - $overhang + $common_rafter_run_to_fascia; dxf_line($x1,$y1,$x2,$y2); # draw left dog leg valley fascia line at 45 wall $x1 = $originX; $y1 = $originY; $x2 = $originX - $offset; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw right dog leg valley fascia line at 45 wall $x1 = $originX + $projection + $face_wall + $projection; $y1 = $originY; $x2 = $originX + $projection + $face_wall + $projection + $offset; $y2 = $originY - $overhang; dxf_line($x1,$y1,$x2,$y2); # draw jack rafters on face wall if($face_wall_half >= $jack_spacing){ if($jack_spacing * 2 > $face_wall_half){ $jack_offset = (($face_wall_half + $offset)/2) * tan($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); # draw face wall left jack rafter $x1 = $originX + $run - (($face_wall_half + $offset)/2); $y1 = $originY - $projection - $overhang; $x2 = $originX + $run - (($face_wall_half + $offset)/2); $y2 = $originY - $projection - $overhang + $jack_offset; dxf_line($x1,$y1,$x2,$y2); $common_jackrafter_length = $jack_offset / cos(atan($pitch / 12)); print "\n\n Face Wall Common Jack Rafter # 1 = " .convertTOfeet($common_jackrafter_length) if($common_jackrafter_length > 0); # draw face wall right jack rafter $x1 = $originX + $run + (($face_wall_half + $offset)/2); $y1 = $originY - $projection - $overhang; $x2 = $originX + $run + (($face_wall_half + $offset)/2); $y2 = $originY - $projection - $overhang + $jack_offset; dxf_line($x1,$y1,$x2,$y2); } else{ # draw face wall left jack rafter $max = floor($face_wall_half / $jack_spacing); for($i=1; $i<= $max; $i++){ $jack_offset = (($face_wall_half-$bay_hip_rafter_offset_at_face_wall_corner) - ($jack_spacing * $i)) * tan($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $x1 = $originX + $run - ($jack_spacing * $i); $y1 = $originY - $projection - $overhang; $x2 = $originX + $run - ($jack_spacing * $i); $y2 = $originY - $projection + $jack_offset; dxf_line($x1,$y1,$x2,$y2); $common_jackrafter_length = $jack_offset / cos(atan($pitch / 12)); print "\n\n Face Wall Common Jack Rafter # $i = " .convertTOfeet($common_jackrafter_length) if($common_jackrafter_length > 0); # draw face wall right jack rafter $x1 = $originX + $run + ($jack_spacing * $i); $y1 = $originY - $projection - $overhang; $x2 = $originX + $run + ($jack_spacing * $i); $y2 = $originY - $projection + $jack_offset; dxf_line($x1,$y1,$x2,$y2); } } } $rx1 = $originX + $run; $ry1 = $originY - $projection + $run; $wall_45_king_common_total_run = ($bay_hip_rafter_run + $overhang_bay_hip_run) * cos($bay_hip_rafter_run_bisect_adj_top_angle_deg * $DEGREE_TO_RAD); $px1 = $wall_45_king_common_total_run * cos(45 * $DEGREE_TO_RAD); $py1 = $wall_45_king_common_total_run * sin(45 * $DEGREE_TO_RAD); $fx1 = $originX + $run - $px1; $fy1 = $originY - $projection + $run - $py1; $sfx1 = $fx1; $sfy1 = $fy1; $sfx2 = $originX + $run + $px1; $sfy2 = $originY - $projection + $run - $py1; # draw left 45 wall king common $x1 = $originX + $run; $y1 = $originY - $projection + $run; $x2 = $fx1; $y2 = $fy1; dxf_line($x1,$y1,$x2,$y2); # draw right 45 wall king common $x1 = $originX + $run; $y1 = $originY - $projection + $run; $x2 = $originX + $run + $px1; $y2 = $originY - $projection + $run - $py1; $sfx2 = $x2; $sfy2 = $y2; dxf_line($x1,$y1,$x2,$y2); # draw jack rafters on 45 wall to front face wall bay hip rafter if($half_projection_wall_length >= $jack_spacing){ # draw 45 wall jack rafters $max = floor($half_projection_wall_length / $jack_spacing); for($i=1; $i<= $max; $i++){ # front side jack rafters $t_length = ($jack_spacing * $i) / cos($bay_hip_rafter_run_bisect_adj_angle_deg * $DEGREE_TO_RAD); $jack_offset = ($half_projection_wall_length - ($jack_spacing * $i)) * tan($bay_hip_rafter_run_bisect_adj_angle_deg * $DEGREE_TO_RAD); $common_jackrafter_length = $jack_offset / cos($Minor_Pitch); print "\n\n 45 Wall Common Jack Rafter # $i = " .convertTOfeet($common_jackrafter_length) if($common_jackrafter_length > 0); $pxx1 = $t_length * cos($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $pyy1 = $t_length * sin($bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $px1 = ($jack_spacing * $i) * cos(45 * $DEGREE_TO_RAD); $py1 = ($jack_spacing * $i) * sin(45 * $DEGREE_TO_RAD); $x1 = $originX + $run - $pxx1; $y1 = $originY - $projection + $run - $pyy1; $x2 = $sfx1 + $px1; $y2 = $sfy1 - $py1; dxf_line($x1,$y1,$x2,$y2); # front side left $x1 = $originX + $run + $pxx1; $y1 = $originY - $projection + $run - $pyy1; $x2 = $sfx2 - $px1; $y2 = $sfy2 - $py1; dxf_line($x1,$y1,$x2,$y2); # front side right # back side jackrafters -- back bay hip is at different angle than the front face wall bay hip rafters $t_length = ($jack_spacing * $i) / cos($wall_bay_hip_rafter_run_bisect_angle_deg * $DEGREE_TO_RAD); $jack_offset = ($half_projection_wall_length - ($jack_spacing * $i)) * tan($wall_bay_hip_rafter_run_bisect_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) if($common_jackrafter_length > 0); $pxx1 = $t_length * cos($wall_bay_hip_rafter_run_top_adj_angle_deg * $DEGREE_TO_RAD);# point at hip $pyy1 = $t_length * sin($wall_bay_hip_rafter_run_top_adj_angle_deg * $DEGREE_TO_RAD);# point at hip $px1 = ($jack_spacing * $i) * cos(45 * $DEGREE_TO_RAD); # point at fascia line $py1 = ($jack_spacing * $i) * sin(45 * $DEGREE_TO_RAD); # point at fascia line $x1 = $originX + $run - $pxx1; # point at hip $y1 = $originY - $projection + $run - $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 + $run + $pxx1; # point at hip $y1 = $originY - $projection + $run - $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; }