Calculate Length of Rafters for Roof

Calculate Rafter Length for Your Roof | Expert Guide & Calculator :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ccc; –card-background: #fff; –shadow: 0 2px 5px rgba(0,0,0,0.1); } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(–background-color); color: var(–text-color); line-height: 1.6; margin: 0; padding: 0; } .container { max-width: 960px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } header { background-color: var(–primary-color); color: white; padding: 20px 0; text-align: center; margin-bottom: 20px; border-radius: 8px 8px 0 0; } header h1 { margin: 0; font-size: 2.2em; } .calculator-section { margin-bottom: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .calculator-section h2 { color: var(–primary-color); text-align: center; margin-bottom: 25px; font-size: 1.8em; } .loan-calc-container { display: flex; flex-direction: column; gap: 20px; } .input-group { display: flex; flex-direction: column; gap: 8px; } .input-group label { font-weight: bold; color: var(–primary-color); } .input-group input[type="number"], .input-group select { padding: 12px; border: 1px solid var(–border-color); border-radius: 5px; font-size: 1em; transition: border-color 0.3s ease; } .input-group input[type="number"]:focus, .input-group select:focus { border-color: var(–primary-color); outline: none; } .input-group .helper-text { font-size: 0.85em; color: #666; } .error-message { color: red; font-size: 0.85em; margin-top: 5px; display: none; /* Hidden by default */ } .button-group { display: flex; gap: 15px; margin-top: 25px; justify-content: center; flex-wrap: wrap; } .btn { padding: 12px 25px; border: none; border-radius: 5px; font-size: 1em; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; text-decoration: none; color: white; } .btn-primary { background-color: var(–primary-color); } .btn-primary:hover { background-color: #003366; transform: translateY(-2px); } .btn-success { background-color: var(–success-color); } .btn-success:hover { background-color: #218838; transform: translateY(-2px); } .btn-secondary { background-color: #6c757d; } .btn-secondary:hover { background-color: #5a6268; transform: translateY(-2px); } .result-container { margin-top: 30px; padding: 25px; background-color: var(–primary-color); color: white; border-radius: 8px; text-align: center; box-shadow: inset 0 0 10px rgba(0,0,0,0.2); } .result-container h3 { margin-top: 0; font-size: 1.5em; color: white; } .main-result { font-size: 2.5em; font-weight: bold; margin: 10px 0; display: block; } .intermediate-results { display: flex; justify-content: space-around; flex-wrap: wrap; margin-top: 20px; gap: 15px; } .intermediate-results div { text-align: center; } .intermediate-results span { display: block; font-size: 1.8em; font-weight: bold; } .intermediate-results p { margin: 0; font-size: 0.9em; opacity: 0.9; } .formula-explanation { margin-top: 20px; font-size: 0.9em; opacity: 0.8; text-align: center; } .chart-container { margin-top: 30px; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); text-align: center; } .chart-container h3 { color: var(–primary-color); margin-bottom: 15px; } canvas { max-width: 100%; height: auto; } .table-container { margin-top: 30px; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); overflow-x: auto; } .table-container h3 { color: var(–primary-color); text-align: center; margin-bottom: 15px; } table { width: 100%; border-collapse: collapse; margin-top: 15px; } th, td { padding: 12px 15px; text-align: left; border-bottom: 1px solid #ddd; } th { background-color: var(–primary-color); color: white; font-weight: bold; } tr:nth-child(even) { background-color: #f2f2f2; } tr:hover { background-color: #e2e2e2; } .article-section { margin-top: 40px; padding: 30px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .article-section h2 { color: var(–primary-color); margin-bottom: 20px; font-size: 1.8em; border-bottom: 2px solid var(–primary-color); padding-bottom: 10px; } .article-section h3 { color: var(–primary-color); margin-top: 25px; margin-bottom: 15px; font-size: 1.4em; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section ul, .article-section ol { padding-left: 25px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; padding: 15px; background-color: #eef; border-left: 4px solid var(–primary-color); border-radius: 5px; } .faq-item strong { color: var(–primary-color); display: block; margin-bottom: 5px; } .internal-links { margin-top: 30px; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: var(–shadow); } .internal-links h3 { color: var(–primary-color); text-align: center; margin-bottom: 15px; } .internal-links ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 10px; } .internal-links li { background-color: #f0f0f0; padding: 10px 15px; border-radius: 5px; transition: background-color 0.3s ease; } .internal-links li:hover { background-color: #e0e0e0; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links span { font-size: 0.9em; color: #555; display: block; margin-top: 5px; } footer { text-align: center; margin-top: 40px; padding: 20px; font-size: 0.9em; color: #777; } @media (min-width: 768px) { .container { margin: 30px auto; } .calculator-section, .article-section, .chart-container, .table-container, .internal-links { padding: 40px; } .loan-calc-container { flex-direction: row; flex-wrap: wrap; justify-content: space-between; } .loan-calc-container .input-group { width: calc(50% – 10px); /* Two columns for inputs */ } .loan-calc-container .input-group:nth-child(3), .loan-calc-container .input-group:nth-child(4) { margin-top: 0; } .button-group { flex-wrap: nowrap; } .intermediate-results { justify-content: space-between; } } @media (min-width: 992px) { .loan-calc-container .input-group { width: calc(33.333% – 15px); /* Three columns for inputs */ } }

Calculate Rafter Length for Your Roof

Roof Rafter Length Calculator

The horizontal distance from the ridge to the wall plate.
The vertical distance from the wall plate to the ridge.
The length the rafter extends beyond the wall.
Commonly 1.5 inches (for 2x lumber).
Enter as Rise/Run (e.g., 6/12, 8/12).
Angle for the plumb cut at the wall plate (usually 90° for square cuts).

Your Rafter Calculation Results

0

Adjusted Run (ft)

0

Adjusted Rise (ft)

0

Ridge Cut Angle (°)

0

Total Rafter Length (ft)

Rafter Length = sqrt( (Adjusted Run)^2 + (Adjusted Rise)^2 ) + Overhang. Ridge Cut Angle is derived from roof pitch.

Results copied successfully!

Rafter Geometry Visualization

Visual representation of your roof's run, rise, and calculated rafter length.

Key Calculation Values

Parameter Value Unit
Horizontal Run 0 ft
Vertical Rise 0 ft
Eave Overhang 0 ft
Ridge Board Thickness 0 in
Roof Pitch 0 N/A
Adjusted Run 0 ft
Adjusted Rise 0 ft
Ridge Cut Angle 0 °
Total Rafter Length 0 ft

What is Rafter Length Calculation?

Rafter length calculation is the process of determining the precise dimensions of the angled structural members that form the slope of a roof. These members, known as rafters, extend from the ridge (the highest point of the roof) down to the wall plate (the top of the exterior wall). Accurate rafter length calculation is fundamental to constructing a safe, stable, and aesthetically pleasing roof. It ensures that all structural components fit together correctly, the roof has the intended pitch and overhangs, and that materials are used efficiently, minimizing waste.

This calculation is essential for anyone involved in new home construction, home additions, or significant roof renovations. This includes DIY homeowners undertaking ambitious projects, professional builders, carpenters, architects, and structural engineers. Understanding how to calculate rafter length is a core skill in carpentry and construction.

A common misconception is that rafter length is simply the diagonal distance across the roof slope. However, this often overlooks crucial elements like the ridge board thickness, the eave overhang, and the specific angles required for cuts at the ridge and the wall plate. Another misconception is that all roof pitches are standard; in reality, pitches vary widely, and the calculation must adapt to each specific pitch.

Rafter Length Formula and Mathematical Explanation

The calculation of rafter length involves basic trigonometry and the Pythagorean theorem. The core idea is to form a right-angled triangle where the horizontal run and the vertical rise are the two shorter sides (legs), and the rafter itself (before considering overhang and cuts) is the hypotenuse.

Step 1: Determine the Roof Pitch Components Roof pitch is typically expressed as a ratio of rise to run, such as 6/12, meaning for every 12 units of horizontal distance (run), the roof rises 6 units vertically.

Step 2: Calculate the Adjusted Run and Rise The "run" used in the Pythagorean theorem isn't just the horizontal distance to the wall plate; it needs to account for the ridge board. If the ridge board has a thickness 'T', the total horizontal span is divided by 2 to get the run from the center of the ridge to the wall plate. However, for rafter length calculation, we often consider the run from the edge of the ridge board. A simpler approach for calculating the rafter's length from the center of the ridge to the outside of the wall plate is to use the given horizontal run and vertical rise directly, assuming the pitch is consistent. For a more precise calculation involving the ridge board, the run is effectively the horizontal distance from the center of the ridge to the outer edge of the wall plate. The rise is the vertical distance from the wall plate to the center of the ridge. Let's refine this: The horizontal run (R) is the distance from the center of the ridge to the outside of the wall plate. The vertical rise (V) is the distance from the wall plate to the center of the ridge. The length of the rafter from the center of the ridge to the outside of the wall plate (hypotenuse) is calculated using the Pythagorean theorem: Rafter Body Length = sqrt(R^2 + V^2)

Step 3: Account for Overhang The eave overhang (O) is the portion of the rafter that extends beyond the exterior wall. This length is added to the calculated rafter body length. Rafter Length (to end of overhang) = Rafter Body Length + O

Step 4: Calculate Ridge Cut Angle The angle of the cut at the ridge depends on the roof pitch. For a standard plumb cut (perpendicular to the rafter), the angle relative to the rafter's centerline is 90 degrees. The angle of the rafter itself at the ridge, relative to the horizontal, is `atan(Rise / Run)`. The angle needed for the ridge cut (bevel angle) is often related to this pitch angle. A common calculation for the angle of the ridge cut (the angle the saw blade makes with the rafter's edge) is `90 – atan(Rise / Run)` in degrees, or more precisely, the angle needed to sit flush against the ridge board. For a standard 90-degree ridge board, the angle of the rafter's cut surface relative to the rafter's length is `90 – pitch_angle`. The pitch angle in degrees is `atan(Rise/Run) * (180 / PI)`. A simpler way to think about the ridge cut angle is the angle the rafter makes with the horizontal plane. The angle of the rafter itself is `atan(Rise / Run)`. The angle cut on the rafter to meet the ridge board is often a plumb cut, meaning it's perpendicular to the rafter's length. The angle needed to sit flush against the ridge board is `90 – pitch_angle_degrees`. Let's use the calculator's output for clarity: The ridge cut angle displayed is the angle the rafter makes with the horizontal. The angle needed for the saw cut (bevel) is often derived from this.

Step 5: Account for Wall Plate Cut (Birdsmouth) While not directly part of the length calculation, a birdsmouth cut is made where the rafter rests on the wall plate. The angle of this cut also depends on the roof pitch and wall angle.

Final Rafter Length = sqrt( (Run)^2 + (Rise)^2 ) + Overhang (Where Run and Rise are the horizontal and vertical distances from the wall plate to the ridge center).

Variables Table

Variable Meaning Unit Typical Range
Run (R) Horizontal distance from the wall plate to the ridge center. ft 1 to 30+
Rise (V) Vertical distance from the wall plate to the ridge center. ft 1 to 15+
Overhang (O) Length the rafter extends beyond the wall. ft 0.5 to 2+
Ridge Board Thickness (T) Thickness of the ridge board lumber. in 1.5 (for 2x lumber)
Roof Pitch Ratio of Rise to Run (e.g., 6/12). Ratio Varies widely (e.g., 2/12 to 12/12+)
Rafter Length Total length of the rafter including overhang. ft Calculated
Ridge Cut Angle Angle of the rafter at the ridge relative to horizontal. ° Calculated

Practical Examples (Real-World Use Cases)

Example 1: Standard Gable Roof Section

A homeowner is building a small shed with a simple gable roof. They measure the dimensions:

  • Horizontal Run (from wall plate to ridge center): 8 ft
  • Vertical Rise (from wall plate to ridge center): 4 ft
  • Eave Overhang: 1 ft
  • Ridge Board Thickness: 1.5 in (standard 2x lumber)
  • Roof Pitch: 4/12 (4 ft rise for 12 ft hypothetical run, but we use actual run/rise)

Calculation:

  • Adjusted Run = 8 ft
  • Adjusted Rise = 4 ft
  • Rafter Body Length = sqrt(8^2 + 4^2) = sqrt(64 + 16) = sqrt(80) ≈ 8.94 ft
  • Total Rafter Length = 8.94 ft + 1 ft (overhang) = 9.94 ft
  • Ridge Cut Angle ≈ atan(4/8) ≈ 26.57°

Interpretation: For this section of the shed roof, each rafter needs to be approximately 9.94 feet long from the peak cut to the end of the overhang. The angle at the ridge will be approximately 26.57 degrees relative to the horizontal. Carpenters would typically add a small amount for saw kerfs and ensure precise cuts.

Example 2: Steeper Roof with Larger Overhang

A contractor is working on a house addition requiring a steeper roof pitch.

  • Horizontal Run (from wall plate to ridge center): 10 ft
  • Vertical Rise (from wall plate to ridge center): 10 ft (a 10/12 pitch)
  • Eave Overhang: 1.5 ft
  • Ridge Board Thickness: 1.5 in
  • Roof Pitch: 10/12

Calculation:

  • Adjusted Run = 10 ft
  • Adjusted Rise = 10 ft
  • Rafter Body Length = sqrt(10^2 + 10^2) = sqrt(100 + 100) = sqrt(200) ≈ 14.14 ft
  • Total Rafter Length = 14.14 ft + 1.5 ft (overhang) = 15.64 ft
  • Ridge Cut Angle ≈ atan(10/10) = 45°

Interpretation: For this steeper roof section, the rafters need to be significantly longer, around 15.64 feet. The 45-degree angle at the ridge indicates a steep pitch, which requires careful handling and cutting. The larger overhang also adds to the overall length and complexity.

How to Use This Rafter Length Calculator

Our Rafter Length Calculator is designed for simplicity and accuracy. Follow these steps to get your required rafter dimensions:

  1. Enter Horizontal Run: Input the horizontal distance from the edge of the ridge board (or center, depending on your framing plan) to the outside edge of the wall plate in feet.
  2. Enter Vertical Rise: Input the vertical height from the top of the wall plate to the center of the ridge in feet.
  3. Enter Eave Overhang: Specify how far you want the rafter to extend beyond the exterior wall line in feet.
  4. Enter Ridge Board Thickness: Input the thickness of the lumber used for the ridge board (typically 1.5 inches for 2x lumber). This is used for context and potential adjustments in more complex calculations, though our primary formula uses the direct run/rise.
  5. Enter Roof Pitch: Input your desired roof pitch in the format "Rise/Run" (e.g., "6/12", "8/12"). This helps contextualize the calculation and derive the ridge cut angle.
  6. Enter Rafter Tail Cut Angle: Input the angle for the cut at the wall plate end. For a standard square cut into the birdsmouth, this is often 90 degrees relative to the rafter's length.
  7. Click 'Calculate Rafter Length': The calculator will instantly process your inputs.

Reading the Results:

  • Primary Result (Total Rafter Length): This is the most critical number – the total length from the apex cut at the ridge to the very end of the overhang.
  • Intermediate Values: These show the adjusted run and rise used in the calculation, along with the calculated ridge cut angle, providing insight into the geometry.
  • Key Assumptions: The formula used (Pythagorean theorem plus overhang) is displayed for transparency.

Decision-Making Guidance: Use the calculated rafter length as your primary cutting dimension. Always double-check measurements on-site. Remember to account for the angle of the birdsmouth cut where the rafter meets the wall plate and the specific angle for the ridge cut (bevel angle) when setting up your saw. It's often wise to cut a test rafter first to verify fit before cutting all your rafters. Consider adding a small buffer (e.g., an inch or two) to the final length for adjustments or potential errors, especially for longer rafters.

Key Factors That Affect Rafter Length Results

Several factors influence the final calculated rafter length and the overall roof structure:

  • Roof Pitch: This is the most significant factor. Steeper pitches (higher rise-to-run ratios) require longer rafters for the same horizontal span. A 12/12 pitch roof will need considerably longer rafters than a 4/12 pitch roof covering the same horizontal distance. This impacts material cost and structural load.
  • Horizontal Run: The wider the building or the further the ridge is from the wall, the longer the rafter needs to be. This directly affects the base of the right-angled triangle used in calculations. Wider spans may necessitate stronger lumber or intermediate supports.
  • Vertical Rise: Directly related to pitch, a higher rise for a given run means a steeper roof and longer rafters. It also increases the load on the supporting walls.
  • Eave Overhang: This is the portion extending beyond the wall. While it adds length, its primary purpose is to protect the walls from rain and snow, and provide shade. A larger overhang requires a longer rafter.
  • Ridge Board Thickness and Type: While our simplified calculation uses direct run/rise, the actual ridge board (often a 1x or 2x plank) affects the exact point where the rafter attaches. A thicker ridge board might slightly alter the effective run or require a different ridge cut angle for a perfect fit. It also adds structural integrity to the roof peak.
  • Type of Rafter Cut (Ridge and Tail): The angles of the cuts at the ridge (plumb cut, level cut, or a combination) and the tail (birdsmouth cut) are critical for proper assembly. While the calculator provides the ridge angle, the specific birdsmouth cut geometry depends on the wall thickness and desired angle, affecting how the rafter sits on the wall plate. Incorrect cuts can compromise structural integrity and weatherproofing.
  • Hip and Valley Rafters: These are different from common rafters. Hip rafters run diagonally from the corner of the building to the ridge, and valley rafters run from the ridge down to an internal corner. Their lengths and cut angles are calculated differently due to their diagonal orientation.
  • Material Dimensions and Actual Lumber Size: Standard lumber dimensions (e.g., 2×6, 2×8) are nominal. The actual dimensions are slightly smaller. This difference is usually negligible for length calculations but can be important for precise joinery. Always use the actual measured length needed.

Frequently Asked Questions (FAQ)

Q1: What is the difference between run and rafter length?

The 'run' is the horizontal distance from the wall plate to the center of the ridge. The 'rafter length' is the actual length of the structural member, including the run, rise, and any overhang, measured along its longest edge.

Q2: Do I need to account for the ridge board in my rafter length calculation?

Yes, indirectly. The 'run' typically refers to the distance from the center of the ridge to the wall plate. The ridge board's thickness influences the exact attachment point and the angle of the ridge cut. Our calculator uses the provided run and rise directly for the Pythagorean calculation, which is standard practice, but understanding the ridge board's role is important for accurate cutting.

Q3: How do I calculate the angle for the ridge cut?

The angle the rafter makes with the horizontal is `atan(Rise / Run)`. The angle needed for the saw blade (bevel angle) to make a plumb cut against the ridge board is typically 90 degrees minus this pitch angle. Our calculator provides the pitch angle.

Q4: What is a birdsmouth cut?

A birdsmouth is a notch cut into the rafter where it rests on the wall plate. It provides a secure bearing surface and helps transfer the roof load directly to the wall structure. The angles of the birdsmouth cut depend on the roof pitch and the wall angle.

Q5: Can I use this calculator for hip or valley rafters?

No, this calculator is specifically for common rafters on gable or shed roofs. Hip and valley rafters run diagonally and require different, more complex calculations due to their angles and lengths relative to the building's corners.

Q6: What if my roof pitch isn't a simple ratio like 6/12?

You can still use the calculator by entering the actual horizontal run and vertical rise in feet. The pitch input is mainly for context and deriving the ridge angle. If you know the angle in degrees, you can calculate the equivalent rise/run ratio.

Q7: How much extra length should I add for saw cuts?

It's good practice to add a small amount, perhaps 1/4 inch to 1/2 inch, to the calculated length to account for the thickness of the saw blade (kerf) at the ridge cut and any minor adjustments needed at the tail. Always measure twice and cut once.

Q8: What units should I use for input?

The calculator primarily uses feet (ft) for linear measurements (run, rise, overhang). The ridge board thickness is in inches (in), and the roof pitch is a ratio (e.g., 6/12). Ensure consistency in your measurements.

© 2023 Your Company Name. All rights reserved.

var chartInstance = null; // Global variable to hold chart instance function validateInput(id, min, max, errorMessageId, helperTextId) { var input = document.getElementById(id); var errorDiv = document.getElementById(errorMessageId); var helperText = document.getElementById(helperTextId); var value = parseFloat(input.value); var isValid = true; errorDiv.style.display = 'none'; input.style.borderColor = 'var(–border-color)'; if (helperText) helperText.style.display = 'block'; if (isNaN(value)) { errorDiv.textContent = 'Please enter a valid number.'; errorDiv.style.display = 'block'; input.style.borderColor = 'red'; if (helperText) helperText.style.display = 'none'; isValid = false; } else if (value max) { errorDiv.textContent = 'Value cannot be greater than ' + max + '.'; errorDiv.style.display = 'block'; input.style.borderColor = 'red'; if (helperText) helperText.style.display = 'none'; isValid = false; } return isValid; } function parseRoofPitch(pitchString) { var parts = pitchString.split('/'); if (parts.length === 2) { var rise = parseFloat(parts[0]); var run = parseFloat(parts[1]); if (!isNaN(rise) && !isNaN(run) && run !== 0) { return { rise: rise, run: run, valid: true }; } } return { rise: 0, run: 0, valid: false }; } function calculateRafters() { var run = parseFloat(document.getElementById('run').value); var rise = parseFloat(document.getElementById('rise').value); var overhang = parseFloat(document.getElementById('overhang').value); var ridgeBoardThickness = parseFloat(document.getElementById('ridgeBoardThickness').value); var roofPitchStr = document.getElementById('roofPitch').value; var rafterTailCut = parseFloat(document.getElementById('rafterTailCut').value); var runError = document.getElementById('runError'); var riseError = document.getElementById('riseError'); var overhangError = document.getElementById('overhangError'); var ridgeBoardThicknessError = document.getElementById('ridgeBoardThicknessError'); var roofPitchError = document.getElementById('roofPitchError'); var rafterTailCutError = document.getElementById('rafterTailCutError'); var isValid = true; // Reset errors runError.style.display = 'none'; document.getElementById('run').style.borderColor = 'var(–border-color)'; riseError.style.display = 'none'; document.getElementById('rise').style.borderColor = 'var(–border-color)'; overhangError.style.display = 'none'; document.getElementById('overhang').style.borderColor = 'var(–border-color)'; ridgeBoardThicknessError.style.display = 'none'; document.getElementById('ridgeBoardThickness').style.borderColor = 'var(–border-color)'; roofPitchError.style.display = 'none'; document.getElementById('roofPitch').style.borderColor = 'var(–border-color)'; rafterTailCutError.style.display = 'none'; document.getElementById('rafterTailCut').style.borderColor = 'var(–border-color)'; if (isNaN(run) || run <= 0) { runError.textContent = 'Please enter a valid positive run.'; runError.style.display = 'block'; document.getElementById('run').style.borderColor = 'red'; isValid = false; } if (isNaN(rise) || rise <= 0) { riseError.textContent = 'Please enter a valid positive rise.'; riseError.style.display = 'block'; document.getElementById('rise').style.borderColor = 'red'; isValid = false; } if (isNaN(overhang) || overhang < 0) { overhangError.textContent = 'Please enter a valid overhang (0 or positive).'; overhangError.style.display = 'block'; document.getElementById('overhang').style.borderColor = 'red'; isValid = false; } if (isNaN(ridgeBoardThickness) || ridgeBoardThickness <= 0) { ridgeBoardThicknessError.textContent = 'Please enter a valid positive ridge board thickness.'; ridgeBoardThicknessError.style.display = 'block'; document.getElementById('ridgeBoardThickness').style.borderColor = 'red'; isValid = false; } if (isNaN(rafterTailCut) || rafterTailCut 180) { rafterTailCutError.textContent = 'Please enter a valid angle between 0 and 180 degrees.'; rafterTailCutError.style.display = 'block'; document.getElementById('rafterTailCut').style.borderColor = 'red'; isValid = false; } var pitchData = parseRoofPitch(roofPitchStr); if (!pitchData.valid) { roofPitchError.textContent = 'Invalid pitch format. Use Rise/Run (e.g., 6/12).'; roofPitchError.style.display = 'block'; document.getElementById('roofPitch').style.borderColor = 'red'; isValid = false; } if (!isValid) { return; } var adjustedRun = run; // For simplicity, using the direct run input var adjustedRise = rise; // For simplicity, using the direct rise input var rafterBodyLength = Math.sqrt(Math.pow(adjustedRun, 2) + Math.pow(adjustedRise, 2)); var totalRafterLength = rafterBodyLength + overhang; // Calculate Ridge Cut Angle (angle with horizontal) var ridgeAngleRad = Math.atan(adjustedRise / adjustedRun); var ridgeAngleDeg = ridgeAngleRad * (180 / Math.PI); document.getElementById('calculatedRun').textContent = adjustedRun.toFixed(2); document.getElementById('calculatedRise').textContent = adjustedRise.toFixed(2); document.getElementById('ridgeCutAngle').textContent = ridgeAngleDeg.toFixed(2); document.getElementById('rafterLength').textContent = totalRafterLength.toFixed(2); document.getElementById('resultContainer').style.display = 'block'; // Update table document.getElementById('tableRun').textContent = run.toFixed(2); document.getElementById('tableRise').textContent = rise.toFixed(2); document.getElementById('tableOverhang').textContent = overhang.toFixed(2); document.getElementById('tableRidgeBoard').textContent = ridgeBoardThickness.toFixed(2); document.getElementById('tableRoofPitch').textContent = roofPitchStr; document.getElementById('tableAdjRun').textContent = adjustedRun.toFixed(2); document.getElementById('tableAdjRise').textContent = adjustedRise.toFixed(2); document.getElementById('tableRidgeAngle').textContent = ridgeAngleDeg.toFixed(2); document.getElementById('tableRafterLength').textContent = totalRafterLength.toFixed(2); updateChart(adjustedRun, adjustedRise, totalRafterLength); } function resetCalculator() { document.getElementById('run').value = '12'; document.getElementById('rise').value = '6'; document.getElementById('overhang').value = '1'; document.getElementById('ridgeBoardThickness').value = '1.5'; document.getElementById('roofPitch').value = '6/12'; document.getElementById('rafterTailCut').value = '90'; document.getElementById('runError').style.display = 'none'; document.getElementById('run').style.borderColor = 'var(–border-color)'; document.getElementById('riseError').style.display = 'none'; document.getElementById('rise').style.borderColor = 'var(–border-color)'; document.getElementById('overhangError').style.display = 'none'; document.getElementById('overhang').style.borderColor = 'var(–border-color)'; document.getElementById('ridgeBoardThicknessError').style.display = 'none'; document.getElementById('ridgeBoardThickness').style.borderColor = 'var(–border-color)'; document.getElementById('roofPitchError').style.display = 'none'; document.getElementById('roofPitch').style.borderColor = 'var(–border-color)'; document.getElementById('rafterTailCutError').style.display = 'none'; document.getElementById('rafterTailCut').style.borderColor = 'var(–border-color)'; document.getElementById('resultContainer').style.display = 'none'; document.getElementById('copySuccess').style.display = 'none'; // Reset table document.getElementById('tableRun').textContent = '0.00'; document.getElementById('tableRise').textContent = '0.00'; document.getElementById('tableOverhang').textContent = '0.00'; document.getElementById('tableRidgeBoard').textContent = '0.00'; document.getElementById('tableRoofPitch').textContent = '0/12'; document.getElementById('tableAdjRun').textContent = '0.00'; document.getElementById('tableAdjRise').textContent = '0.00'; document.getElementById('tableRidgeAngle').textContent = '0.00'; document.getElementById('tableRafterLength').textContent = '0.00'; if (chartInstance) { chartInstance.destroy(); chartInstance = null; } } function copyResults() { var run = document.getElementById('run').value; var rise = document.getElementById('rise').value; var overhang = document.getElementById('overhang').value; var ridgeBoardThickness = document.getElementById('ridgeBoardThickness').value; var roofPitch = document.getElementById('roofPitch').value; var calculatedRun = document.getElementById('calculatedRun').textContent; var calculatedRise = document.getElementById('calculatedRise').textContent; var ridgeCutAngle = document.getElementById('ridgeCutAngle').textContent; var rafterLength = document.getElementById('rafterLength').textContent; var textToCopy = "Rafter Length Calculation Results:\n\n"; textToCopy += "Inputs:\n"; textToCopy += "- Horizontal Run: " + run + " ft\n"; textToCopy += "- Vertical Rise: " + rise + " ft\n"; textToCopy += "- Eave Overhang: " + overhang + " ft\n"; textToCopy += "- Ridge Board Thickness: " + ridgeBoardThickness + " in\n"; textToCopy += "- Roof Pitch: " + roofPitch + "\n\n"; textToCopy += "Calculated Values:\n"; textToCopy += "- Adjusted Run: " + calculatedRun + " ft\n"; textToCopy += "- Adjusted Rise: " + calculatedRise + " ft\n"; textToCopy += "- Ridge Cut Angle: " + ridgeCutAngle + "°\n"; textToCopy += "- Total Rafter Length: " + rafterLength + " ft\n\n"; textToCopy += "Formula Used: Rafter Length = sqrt( (Adjusted Run)^2 + (Adjusted Rise)^2 ) + Overhang"; navigator.clipboard.writeText(textToCopy).then(function() { var successMessage = document.getElementById('copySuccess'); successMessage.style.display = 'block'; setTimeout(function() { successMessage.style.display = 'none'; }, 3000); }).catch(function(err) { console.error('Failed to copy text: ', err); alert('Failed to copy results. Please copy manually.'); }); } function updateChart(run, rise, rafterLength) { var ctx = document.getElementById('rafterChart').getContext('2d'); // Destroy previous chart instance if it exists if (chartInstance) { chartInstance.destroy(); } // Calculate points for the rafter line var startPoint = { x: 0, y: 0 }; // Starting at the wall plate base var ridgePoint = { x: run, y: rise }; // The ridge point var overhangPoint = { x: run + (run * (overhang / Math.sqrt(Math.pow(run, 2) + Math.pow(rise, 2)))), y: rise + (rise * (overhang / Math.sqrt(Math.pow(run, 2) + Math.pow(rise, 2)))) }; // End of overhang, proportional extension // Adjust overhangPoint calculation for clarity: extend proportionally along the rafter line var rafterAngleRad = Math.atan(rise / run); var overhangExtensionX = overhang * Math.cos(rafterAngleRad); var overhangExtensionY = overhang * Math.sin(rafterAngleRad); var endOfRafterPoint = { x: run + overhangExtensionX, y: rise + overhangExtensionY }; chartInstance = new Chart(ctx, { type: 'scatter', data: { datasets: [{ label: 'Roof Structure', data: [ { x: 0, y: 0 }, // Wall plate base { x: run, y: rise }, // Ridge point { x: endOfRafterPoint.x, y: endOfRafterPoint.y } // End of overhang ], backgroundColor: 'rgba(0, 74, 153, 0.8)', // Primary color borderColor: 'rgba(0, 74, 153, 1)', borderWidth: 2, pointRadius: 6, showLine: true, fill: false }, { label: 'Horizontal Run', data: [{ x: 0, y: 0 }, { x: run, y: 0 }], borderColor: 'rgba(40, 167, 69, 0.7)', // Success color borderWidth: 3, pointRadius: 0, showLine: true, fill: false }, { label: 'Vertical Rise', data: [{ x: run, y: 0 }, { x: run, y: rise }], borderColor: 'rgba(108, 117, 125, 0.7)', // Secondary color borderWidth: 3, pointRadius: 0, showLine: true, fill: false } ] }, options: { responsive: true, maintainAspectRatio: true, aspectRatio: 1.5, // Adjust aspect ratio for better visualization scales: { x: { type: 'linear', position: 'bottom', title: { display: true, text: 'Horizontal Run (ft)' }, min: 0, max: Math.max(run * 1.5, endOfRafterPoint.x * 1.1) // Dynamic max }, y: { title: { display: true, text: 'Vertical Rise (ft)' }, min: 0, max: Math.max(rise * 1.5, endOfRafterPoint.y * 1.1) // Dynamic max } }, plugins: { title: { display: true, text: 'Rafter Geometry', font: { size: 16 } }, legend: { position: 'top', } }, tooltips: { callbacks: { label: function(tooltipItem, data) { var label = data.datasets[tooltipItem.datasetIndex].label || "; if (label) { label += ': '; } label += tooltipItem.yLabel + ' ft'; return label; } } } } }); } // Initial calculation on load document.addEventListener('DOMContentLoaded', function() { calculateRafters(); // Add event listeners for real-time updates var inputs = document.querySelectorAll('.loan-calc-container input'); for (var i = 0; i < inputs.length; i++) { inputs[i].addEventListener('input', calculateRafters); } // Add listener for pitch input specifically document.getElementById('roofPitch').addEventListener('input', calculateRafters); });

Leave a Comment