Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Dec 27, 2024
1 parent 1f41a47 commit f87ca1f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 56 deletions.
2 changes: 1 addition & 1 deletion dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mathaven.js

Large diffs are not rendered by default.

51 changes: 2 additions & 49 deletions src/diagram/throw_gpt4o.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,55 +64,8 @@ export class CollisionThrowPlot {
const bpos = straight.applyAxisAngle(up, ϕ)
const b = new Ball(bpos);

//this.log("---original---")
//let result = this.throwAngle(v, ωx, ωz, ϕ)
//this.log("")
//this.log("---new code")
const target:string = "plot"
if (target == "actual") {
Collision.model.updateVelocities(a, b)
return Math.atan2(-Collision.model.tangentialImpulse, Collision.model.normalImpulse)
}
return this.updateVelocities(a, b)
}

private updateVelocities(a: Ball, b: Ball) {

const ab = b.pos.clone().sub(a.pos).normalize();
const abTangent = new Vector3(-ab.y, ab.x, 0);

const R: number = 0.029
const vPoint = a.vel.clone().sub(b.vel).add(
ab.clone().multiplyScalar(-R).cross(a.rvel).sub(
ab.clone().multiplyScalar(R).cross(b.rvel)
)
);

const vRelNormalMag = ab.dot(vPoint);
const vRel = vPoint.addScaledVector(ab, -vRelNormalMag)
const vRelMag = vRel.length();
const vRelTangential = abTangent.dot(vRel); // slip velocity perpendicular to line of impact

const μ = this.dynamicFriction(vRelMag);

let normalImpulse = vRelNormalMag;
let tangentialImpulse =
Math.min((μ * vRelNormalMag) / vRelMag, 1 / 7) * (-vRelTangential)

let throwAngle = Math.atan2(tangentialImpulse, normalImpulse)

this.log("vRelMag =", vRelMag);
this.log("μ =", μ);
this.log("tangentialImpulse (numerator)=", tangentialImpulse);
this.log("normalImpulse (denominator)=", normalImpulse);
this.log("throwAngle =", throwAngle);
this.log("")
this.log(`Math.min((μ * vRelNormalMag) / vRelMag, 1 / 7) = ${Math.min((μ * vRelNormalMag) / vRelMag, 1 / 7)}`)
this.log(`(-vRelMag * Math.sign(vRelTangential)) = ${(-vRelMag * Math.sign(vRelTangential))}`)
this.log("vRelNormalMag =", vRelNormalMag);
this.log("vRelTangential =", vRelTangential);

return throwAngle;
Collision.model.updateVelocities(a, b)
return Math.atan2(Collision.model.tangentialImpulse, -Collision.model.normalImpulse)
}

}
6 changes: 2 additions & 4 deletions src/model/physics/collisionthrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export class CollisionThrow {

const μ = this.dynamicFriction(vRelMag);

//let normalImpulse = vRelNormalMag;
//let tangentialImpulse =
// Math.min((μ * vRelNormalMag) / vRelMag, 1 / 7) * (-vRelTangential)

// let normalImpulse = vRelNormalMag;
// let tangentialImpulse = Math.min((μ * vRelNormalMag) / vRelMag, 1 / 7) * (-vRelTangential)
// matches paper when throwAngle = Math.atan2(tangentialImpulse, normalImpulse)

// Normal impulse (inelastic collision)
Expand Down

0 comments on commit f87ca1f

Please sign in to comment.