From d1bc6b0534d0b4b478377248ba86e694d0da9c2b Mon Sep 17 00:00:00 2001 From: aidnem <99768676+aidnem@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:25:56 -0500 Subject: [PATCH] Converts the teeth amount of a gear to the pitch diameter. --- .../math/GearConversionFunctions.java | 45 ++++++++++++++ .../coppercore/math/GearConversionTest.java | 62 +++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 math/src/main/java/coppercore/math/GearConversionFunctions.java create mode 100644 math/src/test/java/coppercore/math/GearConversionTest.java diff --git a/math/src/main/java/coppercore/math/GearConversionFunctions.java b/math/src/main/java/coppercore/math/GearConversionFunctions.java new file mode 100644 index 0000000..ac2d9c1 --- /dev/null +++ b/math/src/main/java/coppercore/math/GearConversionFunctions.java @@ -0,0 +1,45 @@ +package coppercore.math; + +public class GearConversionFunctions { + public static double pitchPulley3mm(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = 3 * teeth / ((double) Math.PI); + return pitchDiameter; + } + + public static double pitchPulley5mm(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = 5 * teeth / ((double) Math.PI); + return pitchDiameter; + } + + public static double pulleyRT25(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = 0.25 * teeth / ((double) Math.PI); + return pitchDiameter; + } + + public static double chainSprocket25(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = 0.25 / (double) Math.sin(Math.PI / teeth); + return pitchDiameter; + } + + public static double chainSprocket35(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = 0.375 / (double) Math.sin(Math.PI / teeth); + return pitchDiameter; + } + + public static double gear20DP(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = (double) teeth / 20; + return pitchDiameter; + } + + public static double gear32DP(int teeth) { + teeth = Math.abs(teeth); + double pitchDiameter = (double) teeth / 32; + return pitchDiameter; + } +} diff --git a/math/src/test/java/coppercore/math/GearConversionTest.java b/math/src/test/java/coppercore/math/GearConversionTest.java new file mode 100644 index 0000000..2607f33 --- /dev/null +++ b/math/src/test/java/coppercore/math/GearConversionTest.java @@ -0,0 +1,62 @@ +package coppercore.math; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class GearConversionTest { + @Test + public void pitchPulley3mmTest() { + Assertions.assertEquals(12 / (Math.PI), GearConversionFunctions.pitchPulley3mm(4)); + Assertions.assertEquals(150 / (Math.PI), GearConversionFunctions.pitchPulley3mm(50)); + Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pitchPulley3mm(0)); + Assertions.assertEquals(21 / (Math.PI), GearConversionFunctions.pitchPulley3mm(-7)); + } + + @Test + public void pitchPulley5mmTest() { + Assertions.assertEquals(20 / (Math.PI), GearConversionFunctions.pitchPulley5mm(4)); + Assertions.assertEquals(250 / (Math.PI), GearConversionFunctions.pitchPulley5mm(50)); + Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pitchPulley5mm(0)); + Assertions.assertEquals(35 / (Math.PI), GearConversionFunctions.pitchPulley5mm(-7)); + } + + @Test + public void pulleyRT25Test() { + Assertions.assertEquals(1 / (Math.PI), GearConversionFunctions.pulleyRT25(4)); + Assertions.assertEquals(13 / (Math.PI), GearConversionFunctions.pulleyRT25(52)); + Assertions.assertEquals(0 / (Math.PI), GearConversionFunctions.pulleyRT25(0)); + Assertions.assertEquals(2 / (Math.PI), GearConversionFunctions.pulleyRT25(-8)); + } + + @Test + public void chainSprocket25Test() { + Assertions.assertEquals( + 0.25 / (1 / Math.sqrt(2)), GearConversionFunctions.chainSprocket25(4)); + Assertions.assertEquals( + 0.25 / (Math.sqrt(3) / 2), GearConversionFunctions.chainSprocket25(3)); + } + + @Test + public void chainSprocket35Test() { + Assertions.assertEquals( + 0.375 / (1 / Math.sqrt(2)), GearConversionFunctions.chainSprocket35(4)); + Assertions.assertEquals( + 0.375 / (Math.sqrt(3) / 2), GearConversionFunctions.chainSprocket35(3)); + } + + @Test + public void gear20DPTest() { + Assertions.assertEquals(0.2, GearConversionFunctions.gear20DP(4)); + Assertions.assertEquals(1, GearConversionFunctions.gear20DP(20)); + Assertions.assertEquals(0, GearConversionFunctions.gear20DP(0)); + Assertions.assertEquals(2.0, GearConversionFunctions.gear20DP(-40)); + } + + @Test + public void gear32DPTest() { + Assertions.assertEquals(0.125, GearConversionFunctions.gear32DP(4)); + Assertions.assertEquals(1.0, GearConversionFunctions.gear32DP(32)); + Assertions.assertEquals(0, GearConversionFunctions.gear32DP(0)); + Assertions.assertEquals(2.0, GearConversionFunctions.gear32DP(-64)); + } +}