Skip to content

Commit

Permalink
Converts the teeth amount of a gear to the pitch diameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
aidnem committed Dec 12, 2024
1 parent ddc04e0 commit d1bc6b0
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
45 changes: 45 additions & 0 deletions math/src/main/java/coppercore/math/GearConversionFunctions.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
62 changes: 62 additions & 0 deletions math/src/test/java/coppercore/math/GearConversionTest.java
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit d1bc6b0

Please sign in to comment.