Skip to content

Commit

Permalink
Figured out up vs. down
Browse files Browse the repository at this point in the history
  • Loading branch information
ftripier committed Aug 31, 2018
1 parent 754f6fe commit e108f7f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ function draw(state: State, ctx: CanvasRenderingContext2D) {
const rodLength = 75;

const ballPosition = [
Math.cos(state.system.theta + Math.PI * 0.5) * (rodLength + ballSize) +
center[0],
Math.sin(state.system.theta + Math.PI * 0.5) * (rodLength + ballSize) +
center[1]
Math.sin(state.system.theta) * (rodLength + ballSize) + center[0],
Math.cos(state.system.theta) * (rodLength + ballSize) + center[1]
];
ctx.clearRect(0, 0, state.width, state.height);
ctx.beginPath();
Expand All @@ -108,9 +106,9 @@ function update(state: State) {
const ballMass = 1;
const rodLength = 1;
const gravity = 0.001;
const gravitationalAcceleration = gravity * Math.sin(state.system.theta);
const gravitationalAcceleration = -gravity * Math.sin(state.system.theta);

state.system.angularVelocity -= gravitationalAcceleration;
state.system.angularVelocity += gravitationalAcceleration;
state.system.theta +=
state.system.angularVelocity * (state.dt / (16 + 2 / 3));
if (Math.abs(state.system.theta - Math.PI * 2) <= EPSILON) {
Expand Down

0 comments on commit e108f7f

Please sign in to comment.