Skip to content

Commit

Permalink
Fix teeth in mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
tervay committed Dec 17, 2023
1 parent 9692a5c commit 68a4bdf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 35 deletions.
40 changes: 20 additions & 20 deletions cypress/e2e/belts.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ describe("Belt Calculator e2e tests", () => {
p2PitchDiameter: 1.5038,
smallerBeltTeeth: 70,
smallerCenter: 4.9149,
smallerP1TeethInMesh: 7.7,
smallerP2TeethInMesh: 11.6,
smallerP1TeethInMesh: "8.0",
smallerP2TeethInMesh: "11.0",
largerBeltTeeth: 75,
largerCenter: 5.4076,
largerP1TeethInMesh: 7.8,
largerP2TeethInMesh: 11.6,
largerP1TeethInMesh: "8.0",
largerP2TeethInMesh: "11.0",
smallerPulleyGap: 3.66,
largerPulleyGap: 4.15,
smallerDiffFromTarget: -0.085,
Expand All @@ -120,12 +120,12 @@ describe("Belt Calculator e2e tests", () => {
p2PitchDiameter: 0.9023,
smallerBeltTeeth: 102,
smallerCenter: 4.8402,
smallerP1TeethInMesh: 7.8,
smallerP2TeethInMesh: 11.8,
smallerP1TeethInMesh: "8.0",
smallerP2TeethInMesh: "11.0",
largerBeltTeeth: 108,
largerCenter: 5.1947,
largerP1TeethInMesh: 7.8,
largerP2TeethInMesh: 11.8,
largerP1TeethInMesh: "8.0",
largerP2TeethInMesh: "11.0",
smallerPulleyGap: 4.09,
largerPulleyGap: 4.44,
smallerDiffFromTarget: "-0.160",
Expand All @@ -145,11 +145,11 @@ describe("Belt Calculator e2e tests", () => {
smallerBeltTeeth: 560,
smallerCenter: 31.8894,
smallerP1TeethInMesh: "8.0",
smallerP2TeethInMesh: "12.0",
smallerP2TeethInMesh: "11.0",
largerBeltTeeth: 565,
largerCenter: 32.1847,
largerP1TeethInMesh: "8.0",
largerP2TeethInMesh: "12.0",
largerP2TeethInMesh: "11.0",
smallerPulleyGap: 31.14,
largerPulleyGap: 31.43,
smallerDiffFromTarget: -0.111,
Expand All @@ -168,12 +168,12 @@ describe("Belt Calculator e2e tests", () => {
p2PitchDiameter: 0.9023,
smallerBeltTeeth: 100,
smallerCenter: 4.7614,
smallerP1TeethInMesh: 7.8,
smallerP2TeethInMesh: 11.7,
smallerP1TeethInMesh: "8.0",
smallerP2TeethInMesh: "11.0",
largerBeltTeeth: 105,
largerCenter: 5.0568,
largerP1TeethInMesh: 7.8,
largerP2TeethInMesh: 11.8,
largerP1TeethInMesh: "8.0",
largerP2TeethInMesh: "11.0",
smallerPulleyGap: 4.01,
largerPulleyGap: "4.30",
smallerDiffFromTarget: -0.239,
Expand All @@ -192,12 +192,12 @@ describe("Belt Calculator e2e tests", () => {
p2PitchDiameter: 0.9023,
smallerBeltTeeth: 110,
smallerCenter: "4.8100",
smallerP1TeethInMesh: 16.1,
smallerP2TeethInMesh: 11.7,
smallerP1TeethInMesh: "16.0",
smallerP2TeethInMesh: "12.0",
largerBeltTeeth: 115,
largerCenter: 5.1055,
largerP1TeethInMesh: 16.1,
largerP2TeethInMesh: 11.7,
largerP1TeethInMesh: "16.0",
largerP2TeethInMesh: "12.0",
smallerPulleyGap: 3.74,
largerPulleyGap: 4.03,
smallerDiffFromTarget: "-0.190",
Expand All @@ -217,11 +217,11 @@ describe("Belt Calculator e2e tests", () => {
smallerBeltTeeth: 100,
smallerCenter: 4.9311,
smallerP1TeethInMesh: "8.0",
smallerP2TeethInMesh: 8.5,
smallerP2TeethInMesh: "8.0",
largerBeltTeeth: 105,
largerCenter: 5.2263,
largerP1TeethInMesh: "8.0",
largerP2TeethInMesh: 8.5,
largerP2TeethInMesh: "8.0",
smallerPulleyGap: 4.31,
largerPulleyGap: 4.61,
smallerDiffFromTarget: -0.069,
Expand Down
49 changes: 38 additions & 11 deletions src/web/calculators/belts/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,48 @@ export function teethInMesh(
center,
pulleyToUse,
});
if (center.scalar === 0) {
if (center.scalar === 0 || pulleyToUse.pitch.scalar === 0) {
logger().fail("center is zero");
return 0;
}
const debug = useDebugger(logger);

const D = Measurement.max(p1.pitchDiameter, p2.pitchDiameter);
const d = Measurement.min(p1.pitchDiameter, p2.pitchDiameter);
debug({ D, d });
const div = D.sub(d).div(center.mul(6));
debug({ div });
return debugAndReturn(
new Measurement(0.5).sub(div).mul(pulleyToUse.teeth).scalar,
logger,
);
let mode: "larger" | "smaller";
if (p1.eq(pulleyToUse)) {
if (p1.teeth > p2.teeth) {
mode = "larger";
} else {
mode = "smaller";
}
} else {
if (p1.teeth > p2.teeth) {
mode = "smaller";
} else {
mode = "larger";
}
}

const P1 = p1.pitchDiameter;
const P2 = p2.pitchDiameter;
const d = P1.sub(P2).div(2).abs();
const a = Math.asin(d.to("in").scalar / center.to("in").scalar);

if (Number.isNaN(a)) {
return 0;
}

if (mode === "larger") {
const cl2 = pulleyToUse.pitchDiameter
.mul(90 - a)
.mul(Math.PI)
.div(180);
return Math.floor(cl2.div(pulleyToUse.pitch).scalar);
} else {
const cl2 = pulleyToUse.pitchDiameter
.mul(90 + a)
.mul(Math.PI)
.div(180);
return Math.floor(cl2.div(pulleyToUse.pitch).scalar);
}
}

export function getTIMFactor(teethInMesh: number): number {
Expand Down
8 changes: 4 additions & 4 deletions src/web/calculators/belts/tests/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ describe("Belt math", () => {
p1: Pulley.fromTeeth(18, mm(3)),
p2: Pulley.fromTeeth(30, mm(3)),
realDistance: inch(5.961),
expectedP1: 8.77295,
expectedP2: 14.621,
expectedP1: 9,
expectedP2: 14,
},
{
p1: Pulley.fromTeeth(14, mm(3)),
p2: Pulley.fromTeeth(60, mm(3)),
realDistance: inch(10.0362),
expectedP1: 6.59792,
expectedP2: 28.276,
expectedP1: 7,
expectedP2: 29,
},
])(
"%p Calculate teeth in mesh",
Expand Down

1 comment on commit 68a4bdf

@tervay
Copy link
Owner Author

@tervay tervay commented on 68a4bdf Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for recalc ready!

✅ Preview
https://recalc-4s59myzco-tervay.vercel.app

Built with commit 68a4bdf.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.