Spur Gear Calculator

Spur Gear Calculator & Analysis – Calculate Gear Ratios and More :root { –primary-color: #004a99; –success-color: #28a745; –background-color: #f8f9fa; –text-color: #333; –border-color: #ddd; –card-background: #fff; –error-color: #dc3545; } 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: 1000px; margin: 20px auto; padding: 20px; background-color: var(–card-background); border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } header { text-align: center; margin-bottom: 30px; padding-bottom: 20px; border-bottom: 1px solid var(–border-color); } h1 { color: var(–primary-color); margin-bottom: 10px; } h2, h3 { color: var(–primary-color); margin-top: 25px; margin-bottom: 15px; } .loan-calc-container { background-color: var(–card-background); padding: 25px; border-radius: 8px; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.08); margin-bottom: 30px; } .input-group { margin-bottom: 20px; text-align: left; } .input-group label { display: block; margin-bottom: 8px; font-weight: bold; color: #555; } .input-group input[type="number"], .input-group select { width: calc(100% – 22px); padding: 10px; border: 1px solid var(–border-color); border-radius: 4px; font-size: 1rem; box-sizing: border-box; } .input-group input[type="number"]:focus, .input-group select:focus { border-color: var(–primary-color); outline: none; box-shadow: 0 0 0 2px rgba(0, 74, 153, 0.2); } .input-group .helper-text { font-size: 0.85em; color: #6c757d; margin-top: 5px; display: block; } .error-message { color: var(–error-color); font-size: 0.85em; margin-top: 5px; display: block; min-height: 1.2em; /* Prevent layout shift */ } .button-group { display: flex; justify-content: space-between; margin-top: 25px; gap: 10px; } .button-group button { padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 1rem; font-weight: bold; transition: background-color 0.3s ease; flex: 1; } #calculateBtn { background-color: var(–primary-color); color: white; } #calculateBtn:hover { background-color: #003366; } #resetBtn { background-color: #6c757d; color: white; } #resetBtn:hover { background-color: #5a6268; } #copyBtn { background-color: #ffc107; color: #212529; } #copyBtn:hover { background-color: #e0a800; } .results-container { margin-top: 30px; padding: 20px; background-color: #e9ecef; border-radius: 8px; border: 1px solid #dee2e6; } .results-container h3 { margin-top: 0; color: var(–primary-color); } #primaryResult { font-size: 2em; font-weight: bold; color: var(–primary-color); background-color: #fff; padding: 15px; border-radius: 5px; text-align: center; margin-bottom: 20px; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1); } .intermediate-results div, .formula-explanation { margin-bottom: 15px; font-size: 0.95em; } .intermediate-results span { font-weight: bold; color: var(–primary-color); } .formula-explanation { font-style: italic; color: #444; border-left: 3px solid var(–primary-color); padding-left: 10px; } table { width: 100%; border-collapse: collapse; margin-top: 20px; margin-bottom: 20px; overflow-x: auto; /* Mobile responsiveness */ display: block; /* Needed for overflow-x */ white-space: nowrap; /* Prevent wrapping in cells */ } th, td { padding: 10px 15px; text-align: left; border: 1px solid var(–border-color); } thead { background-color: var(–primary-color); color: white; } tbody tr:nth-child(even) { background-color: #f2f2f2; } caption { font-size: 1.1em; font-weight: bold; color: var(–primary-color); margin-bottom: 10px; text-align: left; } canvas { max-width: 100%; /* Mobile responsiveness */ height: auto; display: block; /* Remove extra space below canvas */ margin: 20px auto; border: 1px solid var(–border-color); border-radius: 4px; } .chart-container { text-align: center; margin-top: 20px; } .chart-caption { font-size: 0.9em; color: #6c757d; margin-top: 5px; display: block; } .article-section { margin-top: 40px; padding-top: 20px; border-top: 1px solid var(–border-color); } .article-section h2 { text-align: center; margin-bottom: 25px; } .article-section p, .article-section ul, .article-section ol { margin-bottom: 15px; } .article-section li { margin-bottom: 8px; } .faq-item { margin-bottom: 15px; padding: 10px; background-color: #f8f9fa; border-radius: 4px; border: 1px solid #e0e0e0; } .faq-item strong { color: var(–primary-color); cursor: pointer; display: block; } .faq-item p { margin-top: 10px; display: none; /* Hidden by default */ } .faq-item.open p { display: block; } .internal-links { margin-top: 30px; padding: 15px; background-color: #e9ecef; border-radius: 5px; } .internal-links h3 { margin-top: 0; color: var(–primary-color); } .internal-links ul { list-style: none; padding: 0; margin: 0; } .internal-links li { margin-bottom: 10px; } .internal-links a { color: var(–primary-color); text-decoration: none; font-weight: bold; } .internal-links a:hover { text-decoration: underline; } .internal-links span { font-size: 0.9em; color: #6c757d; display: block; margin-top: 3px; } /* Responsive adjustments */ @media (max-width: 768px) { .container { margin: 10px; padding: 15px; } .button-group { flex-direction: column; } .button-group button { width: 100%; } h1 { font-size: 1.8em; } #primaryResult { font-size: 1.8em; } table { font-size: 0.9em; } th, td { padding: 8px 10px; } }

Spur Gear Calculator

Calculate essential spur gear parameters for your mechanical designs.

Spur Gear Parameters

The basic unit of gear size; pitch diameter / number of teeth. Units: mm.
The total number of teeth on the driven gear.
The total number of teeth on the driver gear.
14.5° 20° 25° The angle between the line of action and the common tangent to the pitch circles.

Calculation Results

Gear Ratio:
Pitch Diameter (Driven): mm
Pitch Diameter (Driver): mm
Center Distance: mm
Gear Ratio = Teeth (Driven) / Teeth (Driver)
Pitch Diameter = Module * Number of Teeth
Center Distance = (Pitch Diameter (Driven) + Pitch Diameter (Driver)) / 2

Gear Data Table

Spur Gear Specifications
Parameter Driver Gear Driven Gear
Number of Teeth
Module (mm)
Pressure Angle (°)
Pitch Diameter (mm)
Center Distance (mm)
Gear Ratio

Gear Ratio vs. Teeth Count

Visualizing how gear ratio changes with the number of teeth for a fixed module and pressure angle.

What is a Spur Gear Calculator?

A spur gear calculator is a specialized tool designed to simplify the complex calculations involved in designing and analyzing spur gears. Spur gears are the most basic type of gear, characterized by their cylindrical shape and teeth that are parallel to the axis of rotation. They are widely used in various mechanical applications due to their simplicity, efficiency, and cost-effectiveness. This spur gear calculator helps engineers, designers, and hobbyists quickly determine critical parameters such as gear ratio, pitch diameter, center distance, and more, based on input values like the number of teeth and module.

Who should use it?

  • Mechanical Engineers: For designing new gear trains or verifying existing designs.
  • Product Designers: To ensure proper meshing and functionality of geared components.
  • Students and Educators: For learning and teaching the principles of gear mechanics.
  • DIY Enthusiasts and Makers: For projects involving custom gear systems.

Common Misconceptions:

  • Misconception: All gears are the same. Reality: Spur gears are just one type; others include helical, bevel, and worm gears, each with different applications and characteristics.
  • Misconception: Gear ratio is the only important factor. Reality: While crucial for speed and torque, factors like module, pressure angle, backlash, and material strength are equally vital for performance and durability.
  • Misconception: Spur gears are always noisy. Reality: While they can be noisier than helical gears, proper design, manufacturing, lubrication, and mounting can significantly reduce noise levels.

Spur Gear Calculator Formula and Mathematical Explanation

The calculations performed by a spur gear calculator are based on fundamental geometric principles of gears. Understanding these formulas is key to appreciating the tool's utility.

Core Formulas:

  1. Gear Ratio (i): This is the ratio of the rotational speeds or the number of teeth between the driven gear and the driver gear. It dictates how much the speed is reduced or increased and the corresponding torque multiplication.
    i = N_driven / N_driver
    Where:
    • i is the Gear Ratio
    • N_driven is the Number of Teeth on the Driven Gear
    • N_driver is the Number of Teeth on the Driver Gear
  2. Pitch Diameter (d): This is the theoretical diameter of the gear where meshing occurs. It's a fundamental dimension used to calculate other parameters.
    d = m * N
    Where:
    • d is the Pitch Diameter
    • m is the Module
    • N is the Number of Teeth
  3. Center Distance (a): This is the distance between the centers of two meshing gears. It's critical for ensuring proper engagement and alignment.
    a = (d_driven + d_driver) / 2
    Alternatively, using module:
    a = m * (N_driven + N_driver) / 2
    Where:
    • a is the Center Distance
    • d_driven is the Pitch Diameter of the Driven Gear
    • d_driver is the Pitch Diameter of the Driver Gear
  4. Addendum (h_a): The radial distance from the pitch circle to the top of the tooth.
    h_a = m
  5. Dedendum (h_d): The radial distance from the pitch circle to the bottom of the tooth space.
    h_d = 1.25 * m (Standard value)
  6. Outside Diameter (D_o): The overall diameter of the gear.
    D_o = d + 2 * h_a = m * N + 2 * m = m * (N + 2)
  7. Tooth Thickness (t): The thickness of the tooth measured along the pitch circle.
    t = π * m / 2

Variable Explanations and Typical Ranges:

Variable Meaning Unit Typical Range
m (Module) Basic unit of gear size; pitch diameter divided by the number of teeth. Higher module means larger gears. mm 0.5 – 20+ (depends on application)
N (Number of Teeth) The count of teeth on a gear. Determines gear ratio and pitch diameter. Minimum teeth often limited by avoiding undercutting (typically 17-20 for 20° pressure angle). Count 10 – 200+
α (Pressure Angle) Angle between the line of action and the common tangent to the pitch circles. Affects tooth strength, contact ratio, and undercutting. Degrees 14.5°, 20° (most common), 25°
i (Gear Ratio) Ratio of output speed to input speed (or input teeth to output teeth). Ratio 0.1 – 10+ (depends on application)
d (Pitch Diameter) Theoretical diameter at which gears mesh. mm Varies widely based on module and teeth count.
a (Center Distance) Distance between the centers of two meshing gears. Crucial for proper mounting. mm Varies widely based on pitch diameters.

Practical Examples (Real-World Use Cases)

Let's explore how the spur gear calculator can be applied in practical scenarios.

Example 1: Speed Reduction for a Conveyor Belt

Scenario: An engineer needs to drive a conveyor belt at a slower speed than the motor's output speed. They have a 10 kW motor running at 1800 RPM and need the conveyor to run at approximately 300 RPM. They decide to use spur gears and need to determine the gear parameters.

Inputs:

  • Motor Speed (Driver): 1800 RPM
  • Desired Conveyor Speed (Driven): 300 RPM
  • Module (m): 3 mm (chosen for moderate load capacity)
  • Pressure Angle (α): 20°

Calculations using the calculator:

First, calculate the required Gear Ratio:

Gear Ratio = Input Speed / Output Speed = 1800 RPM / 300 RPM = 6

Now, using the calculator with Gear Ratio = 6, Module = 3 mm, Pressure Angle = 20°:

  • Let's assume a Driver Gear with N_driver = 20 teeth.
  • Then, Driven Gear teeth: N_driven = Gear Ratio * N_driver = 6 * 20 = 120 teeth.

Calculator Outputs:

  • Primary Result (Gear Ratio): 6.0
  • Intermediate Values:
    • Pitch Diameter (Driver): 3 mm * 20 = 60 mm
    • Pitch Diameter (Driven): 3 mm * 120 = 360 mm
    • Center Distance: (60 mm + 360 mm) / 2 = 210 mm

Interpretation: The engineer can use a driver gear with 20 teeth and a driven gear with 120 teeth, both with a module of 3 mm and a 20° pressure angle. The center distance of 210 mm must be maintained between the gear shafts. This setup will provide the required 6:1 speed reduction.

Example 2: Designing a Simple Gearbox for a Robot Arm

Scenario: A robotics team is designing a simple gearbox for a robot arm actuator. They need a compact gear set with a moderate gear reduction. They have limited space and choose a smaller module size.

Inputs:

  • Module (m): 1 mm (for compactness)
  • Pressure Angle (α): 20°
  • Driver Gear Teeth (N_driver): 15
  • Driven Gear Teeth (N_driven): 45

Calculations using the calculator:

Calculator Outputs:

  • Primary Result (Gear Ratio): 45 / 15 = 3.0
  • Intermediate Values:
    • Pitch Diameter (Driver): 1 mm * 15 = 15 mm
    • Pitch Diameter (Driven): 1 mm * 45 = 45 mm
    • Center Distance: (15 mm + 45 mm) / 2 = 30 mm

Interpretation: This configuration provides a 3:1 speed reduction and torque increase. The gears are relatively small (pitch diameters of 15mm and 45mm) and require a center distance of 30mm, making them suitable for a compact robot arm design. The spur gear calculator confirms the feasibility and provides essential dimensions for mounting.

How to Use This Spur Gear Calculator

Using this spur gear calculator is straightforward. Follow these steps to get accurate results for your gear design needs.

  1. Input Module (m): Enter the module value in millimeters. This is a fundamental measure of gear size. If you don't know it, you might need to calculate it based on desired pitch diameter and teeth count.
  2. Input Number of Teeth (Driven & Driver): Enter the number of teeth for both the driven gear and the driver gear. These values directly influence the gear ratio and pitch diameters. Ensure you use whole numbers.
  3. Select Pressure Angle (α): Choose the pressure angle from the dropdown menu (commonly 14.5°, 20°, or 25°). The 20° angle is the most prevalent in modern applications.
  4. Click 'Calculate': Once all fields are populated, click the 'Calculate' button.

How to Read Results:

  • Primary Result (Gear Ratio): This is the main output, showing the ratio of the driven gear's teeth to the driver gear's teeth. A ratio greater than 1 indicates a speed reduction (and torque increase), while a ratio less than 1 indicates a speed increase (and torque decrease).
  • Intermediate Values: These provide crucial dimensions:
    • Pitch Diameter: The effective diameter of the gear where meshing occurs.
    • Center Distance: The distance between the shafts of the two meshing gears. This is critical for physical mounting.
  • Gear Data Table: This table summarizes all key parameters for both gears, offering a clear overview.
  • Chart: The chart visually represents the relationship between the number of teeth and the resulting gear ratio, helping to understand trade-offs.

Decision-Making Guidance:

  • Speed vs. Torque: Use the gear ratio to determine if you are achieving the desired speed reduction or increase and the corresponding torque multiplication.
  • Physical Constraints: Pay close attention to the Center Distance and Pitch Diameters. Ensure they fit within your mechanical assembly's space limitations.
  • Module Selection: A larger module generally indicates a stronger gear capable of handling higher loads, but also results in a larger overall gear size.
  • Pressure Angle: While 20° is standard, 14.5° offers slightly higher contact ratio (smoother operation) but is weaker and more prone to undercutting. 25° offers greater tooth strength but a lower contact ratio.

Key Factors That Affect Spur Gear Results

While the spur gear calculator provides essential geometric data, several real-world factors influence the actual performance and longevity of spur gears:

  1. Material Strength and Hardness: The choice of material (e.g., steel alloys, plastics, bronze) significantly impacts the load-carrying capacity, wear resistance, and operating temperature limits of the gears. Harder materials generally withstand higher stresses.
  2. Manufacturing Tolerances: Precision in manufacturing affects how well the teeth mesh. Tight tolerances reduce backlash (the gap between meshing teeth), leading to quieter operation and less wear, but can increase cost. Poor tolerances can cause noise, vibration, and premature failure.
  3. Lubrication: Proper lubrication is critical for reducing friction, dissipating heat, and preventing wear between meshing teeth. The type of lubricant (oil, grease) and the lubrication method (splash, forced) depend on the operating conditions and gear design. Insufficient lubrication is a primary cause of gear failure.
  4. Operating Load and Speed: The torque and speed at which the gears operate directly affect the stresses on the teeth. Higher loads and speeds generate more heat and stress, potentially leading to bending fatigue, surface wear, or scuffing if the gears are not designed appropriately.
  5. Environmental Conditions: Factors like temperature extremes, humidity, dust, and corrosive elements in the operating environment can affect gear material properties, lubricant performance, and overall lifespan. For instance, high temperatures can degrade lubricants and weaken materials.
  6. Mounting Accuracy and Shaft Rigidity: How accurately the gears are mounted on their shafts and how rigid those shafts are is crucial. Misalignment or shaft deflection under load can cause uneven tooth contact, leading to increased wear, noise, and potential breakage. The center distance calculated must be maintained precisely.
  7. Backlash: The small clearance between mating teeth is necessary to prevent binding and allow for lubrication. However, excessive backlash can lead to noise, impact loads, and reduced positional accuracy, especially in applications like robotics or precision instruments.
  8. Service Factor: This is an empirical multiplier applied to calculations to account for the severity of the application (e.g., uniform, moderate shock, heavy shock loads). It helps ensure the gear design is robust enough for real-world operating conditions beyond simple theoretical calculations.

Frequently Asked Questions (FAQ)

What is the difference between module and diametral pitch?

Module (m) is used in the metric system, where pitch diameter = m * N. Diametral Pitch (DP) is used in the imperial system, where pitch diameter = N / DP. A higher module or DP means a larger gear.

Can I use this calculator for helical gears?

No, this calculator is specifically for spur gears, where teeth are parallel to the axis. Helical gears have teeth cut at an angle and require different calculations involving helix angle.

What does 'undercutting' mean in gears?

Undercutting occurs when the generating tool cuts into the base of the gear tooth, weakening it. It typically happens when a gear has too few teeth for a given pressure angle. Standard calculations usually ensure enough teeth (e.g., minimum 17 for 20° pressure angle) to avoid this.

How does pressure angle affect gear performance?

A larger pressure angle (e.g., 25° vs 20°) results in stronger teeth bases, higher contact ratio (smoother operation), and less tendency for undercutting. However, it can lead to higher bearing loads and potentially more sliding friction.

What is the minimum number of teeth for a spur gear?

The minimum number of teeth is often determined by the pressure angle to avoid undercutting. For a standard 20° pressure angle, it's typically around 17 teeth. For 14.5°, it's around 32 teeth. Using fewer teeth may require profile modification.

How do I calculate the torque capacity of a spur gear?

Calculating torque capacity involves more complex formulas considering bending stress, surface durability (Hertzian stress), material properties, face width, and dynamic factors. This calculator focuses on geometric parameters, not load capacity.

What is backlash, and why is it important?

Backlash is the clearance between mating teeth when gears are fully engaged. It's essential to prevent binding due to manufacturing tolerances, thermal expansion, and lubrication. However, excessive backlash can cause noise and reduce precision.

Can I use different modules for meshing gears?

No, for spur gears to mesh correctly, they must have the same module and pressure angle. The pitch diameters and center distance are then determined by the number of teeth.

How does the calculator handle non-integer results?

The calculator performs calculations using standard floating-point arithmetic. While inputs like teeth count are integers, derived values like pitch diameter or center distance can be non-integers and are displayed with appropriate precision.

© 2023 Your Company Name. All rights reserved.

var moduleInput = document.getElementById('module'); var teethDrivenInput = document.getElementById('teethDriven'); var teethDriverInput = document.getElementById('teethDriver'); var pressureAngleInput = document.getElementById('pressureAngle'); var calculateBtn = document.getElementById('calculateBtn'); var resetBtn = document.getElementById('resetBtn'); var copyBtn = document.getElementById('copyBtn'); var moduleError = document.getElementById('moduleError'); var teethDrivenError = document.getElementById('teethDrivenError'); var teethDriverError = document.getElementById('teethDriverError'); var pressureAngleError = document.getElementById('pressureAngleError'); var primaryResultDiv = document.getElementById('primaryResult'); var gearRatioSpan = document.getElementById('gearRatio').querySelector('span'); var pitchDiameterDrivenSpan = document.getElementById('pitchDiameterDriven').querySelector('span'); var pitchDiameterDriverSpan = document.getElementById('pitchDiameterDriver').querySelector('span'); var centerDistanceSpan = document.getElementById('centerDistance'); var tableTeethDriver = document.getElementById('tableTeethDriver'); var tableTeethDriven = document.getElementById('tableTeethDriven'); var tableModuleDriver = document.getElementById('tableModuleDriver'); var tableModuleDriven = document.getElementById('tableModuleDriven'); var tablePressureAngle = document.getElementById('tablePressureAngle'); var tablePitchDiameterDriver = document.getElementById('tablePitchDiameterDriver'); var tablePitchDiameterDriven = document.getElementById('tablePitchDiameterDriven'); var tableCenterDistance = document.getElementById('tableCenterDistance'); var tableGearRatio = document.getElementById('tableGearRatio'); var gearRatioChart; var chartContext; function validateInput(inputElement, errorElement, min, max) { var value = parseFloat(inputElement.value); var isValid = true; errorElement.textContent = "; if (isNaN(value)) { errorElement.textContent = 'Please enter a valid number.'; isValid = false; } else if (value <= 0) { errorElement.textContent = 'Value must be positive.'; isValid = false; } else if (min !== undefined && value max) { errorElement.textContent = 'Value cannot be greater than ' + max + '.'; isValid = false; } return isValid; } function calculateSpurGear() { var isValid = true; var module = parseFloat(moduleInput.value); var teethDriven = parseInt(teethDrivenInput.value); var teethDriver = parseInt(teethDriverInput.value); var pressureAngle = parseFloat(pressureAngleInput.value); isValid &= validateInput(moduleInput, moduleError, 0.1); // Minimum module isValid &= validateInput(teethDrivenInput, teethDrivenError, 1); // Minimum teeth isValid &= validateInput(teethDriverInput, teethDriverError, 1); // Minimum teeth // Pressure angle is a select, so no range validation needed here unless specific options are restricted if (!isValid) { resetResults(); return; } var gearRatio = teethDriven / teethDriver; var pitchDiameterDriven = module * teethDriven; var pitchDiameterDriver = module * teethDriver; var centerDistance = (pitchDiameterDriven + pitchDiameterDriver) / 2; primaryResultDiv.textContent = gearRatio.toFixed(2); gearRatioSpan.textContent = gearRatio.toFixed(2); pitchDiameterDrivenSpan.textContent = pitchDiameterDriven.toFixed(2); pitchDiameterDriverSpan.textContent = pitchDiameterDriver.toFixed(2); centerDistanceSpan.textContent = centerDistance.toFixed(2) + " mm"; // Update table tableTeethDriver.textContent = teethDriver; tableTeethDriven.textContent = teethDriven; tableModuleDriver.textContent = module.toFixed(2); tableModuleDriven.textContent = module.toFixed(2); tablePressureAngle.textContent = pressureAngle.toFixed(1) + "°"; tablePitchDiameterDriver.textContent = pitchDiameterDriver.toFixed(2); tablePitchDiameterDriven.textContent = pitchDiameterDriven.toFixed(2); tableCenterDistance.textContent = centerDistance.toFixed(2) + " mm"; tableGearRatio.textContent = gearRatio.toFixed(2); updateChart([teethDriver, teethDriven], [gearRatio]); return { gearRatio: gearRatio.toFixed(2), pitchDiameterDriven: pitchDiameterDriven.toFixed(2), pitchDiameterDriver: pitchDiameterDriver.toFixed(2), centerDistance: centerDistance.toFixed(2) }; } function resetResults() { primaryResultDiv.textContent = '–'; gearRatioSpan.textContent = '–'; pitchDiameterDrivenSpan.textContent = '–'; pitchDiameterDriverSpan.textContent = '–'; centerDistanceSpan.textContent = '–'; tableTeethDriver.textContent = '–'; tableTeethDriven.textContent = '–'; tableModuleDriver.textContent = '–'; tableModuleDriven.textContent = '–'; tablePressureAngle.textContent = '–'; tablePitchDiameterDriver.textContent = '–'; tablePitchDiameterDriven.textContent = '–'; tableCenterDistance.textContent = '–'; tableGearRatio.textContent = '–'; // Clear chart if (chartContext) { chartContext.clearRect(0, 0, chartContext.canvas.width, chartContext.canvas.height); } } function resetCalculator() { moduleInput.value = 2; teethDrivenInput.value = 60; teethDriverInput.value = 20; pressureAngleInput.value = 20; moduleError.textContent = "; teethDrivenError.textContent = "; teethDriverError.textContent = "; pressureAngleError.textContent = "; resetResults(); calculateSpurGear(); // Recalculate with defaults } function copyResults() { var results = calculateSpurGear(); // Ensure results are up-to-date if (!results) return; var copyText = "Spur Gear Calculation Results:\n\n"; copyText += "Primary Result (Gear Ratio): " + results.gearRatio + "\n"; copyText += "Pitch Diameter (Driven): " + results.pitchDiameterDriven + " mm\n"; copyText += "Pitch Diameter (Driver): " + results.pitchDiameterDriver + " mm\n"; copyText += "Center Distance: " + results.centerDistance + " mm\n\n"; copyText += "Key Assumptions:\n"; copyText += "- Module: " + moduleInput.value + " mm\n"; copyText += "- Teeth (Driven): " + teethDrivenInput.value + "\n"; copyText += "- Teeth (Driver): " + teethDriverInput.value + "\n"; copyText += "- Pressure Angle: " + pressureAngleInput.value + "°\n"; var textArea = document.createElement("textarea"); textArea.value = copyText; textArea.style.position = "fixed"; textArea.style.left = "-9999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); // Optionally show a confirmation message to the user alert('Results copied to clipboard!'); } catch (err) { console.log('Unable to copy text.', err); alert('Failed to copy results.'); } document.body.removeChild(textArea); } function initChart() { chartContext = document.getElementById('gearRatioChart').getContext('2d'); gearRatioChart = new Chart(chartContext, { type: 'bar', // Changed to bar for better comparison of two values data: { labels: ['Driver Teeth', 'Driven Teeth'], datasets: [{ label: 'Number of Teeth', data: [0, 0], // Initial data backgroundColor: [ 'rgba(0, 74, 153, 0.6)', 'rgba(40, 167, 69, 0.6)' ], borderColor: [ 'rgba(0, 74, 153, 1)', 'rgba(40, 167, 69, 1)' ], borderWidth: 1 }, { label: 'Resulting Gear Ratio', data: [0, 0], // Placeholder for ratio, will be shown as a line or separate bar if needed type: 'line', // Use line for ratio comparison borderColor: 'rgba(255, 193, 7, 1)', backgroundColor: 'rgba(255, 193, 7, 0.5)', fill: false, yAxisID: 'y-axis-ratio' // Assign to a secondary y-axis }] }, options: { responsive: true, maintainAspectRatio: false, // Allow custom aspect ratio scales: { x: { title: { display: true, text: 'Gear Type' } }, y: { title: { display: true, text: 'Number of Teeth' }, beginAtZero: true }, 'y-axis-ratio': { type: 'linear', position: 'right', title: { display: true, text: 'Gear Ratio' }, min: 0, // Adjust min/max as needed max: 10 // Example max, adjust dynamically if needed } }, plugins: { legend: { position: 'top', }, title: { display: true, text: 'Spur Gear Teeth Count vs. Ratio' } } } }); } function updateChart(teethData, ratioData) { if (!gearRatioChart) { initChart(); } var driverTeeth = teethData[0]; var drivenTeeth = teethData[1]; var gearRatio = ratioData[0]; gearRatioChart.data.datasets[0].data = [driverTeeth, drivenTeeth]; // For the ratio line, we can plot it against the teeth count. // A simple approach is to show the ratio value associated with the driven gear. gearRatioChart.data.datasets[1].data = [null, gearRatio]; // Plot ratio only for driven gear for simplicity gearRatioChart.data.labels = ['Driver Teeth (' + driverTeeth + ')', 'Driven Teeth (' + drivenTeeth + ')']; // Adjust y-axis max for ratio if needed var maxTeeth = Math.max(driverTeeth, drivenTeeth); var maxRatio = gearRatio; var yAxisMax = Math.max(maxTeeth, maxRatio * 1.2); // Ensure enough space gearRatioChart.options.scales.y.max = maxTeeth * 1.1; // Adjust teeth axis max gearRatioChart.options.scales['y-axis-ratio'].max = maxRatio * 1.5; // Adjust ratio axis max gearRatioChart.update(); } function toggleFaq(element) { var parent = element.parentElement; parent.classList.toggle('open'); } calculateBtn.onclick = calculateSpurGear; resetBtn.onclick = resetCalculator; copyBtn.onclick = copyResults; // Initial calculation on page load window.onload = function() { resetCalculator(); // Sets defaults and calculates };

Leave a Comment