Skip to content

fix: project velocity and acceleration onto 2D axes in stepAlongPlane#316

Merged
mattqdev merged 1 commit into
physicshub:mainfrom
TechGenius-Karan:fix/inclined-plane-velocity-projection
May 18, 2026
Merged

fix: project velocity and acceleration onto 2D axes in stepAlongPlane#316
mattqdev merged 1 commit into
physicshub:mainfrom
TechGenius-Karan:fix/inclined-plane-velocity-projection

Conversation

@TechGenius-Karan
Copy link
Copy Markdown
Contributor

📘 Pull Request Template – PhysicsHub

Thank you for contributing to PhysicsHub!
Please complete the sections below to help us review your pull request efficiently.


🔍 Description

stepAlongPlane() accepted angleRad as a third argument from its caller but silently discarded it. The 2D state.velocity and state.acceleration were synced as purely horizontal vectors (v, 0) regardless of the plane angle, which is incorrect.

Fixed by accepting angleRad (defaulting to 0) and projecting the scalar plane values onto 2D axes using cos/sin, so state.velocity and state.acceleration correctly reflect the actual direction of motion along the inclined surface.

Closes #BUG-004 (if applicable)


✅ Checklist

Before requesting a review, please ensure that you have:

  • Verified that the project builds and runs locally (npm run dev)
  • Ensured no ESLint or TypeScript warnings/errors remain
  • Updated documentation, comments, or in-code explanations where needed
  • Verified responsiveness across devices (desktop, tablet, mobile)
  • Followed the CONTRIBUTING.md guidelines

🎨 Visual Changes (if UI-related)

IF CHANGES ARE RELATED TO SIMULATIONS PLEASE SEND A SHORT CLIP ABOUT IT
(OBLIGATORY)


📂 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📝 Documentation update
  • ♻️ Refactor / code quality improvement
  • 🎨 UI/UX enhancement
  • 🔒 Security improvement

🧩 Additional Notes for Reviewers

stepAlongPlane() accepted angleRad as a third argument from its caller
but silently discarded it. The 2D state.velocity and state.acceleration
were synced as purely horizontal vectors (v, 0) regardless of the plane
angle, which is incorrect.

Fixed by accepting angleRad (defaulting to 0) and projecting the scalar
plane values onto 2D axes using cos/sin, so state.velocity and
state.acceleration correctly reflect the actual direction of motion
along the inclined surface.
@mattqdev
Copy link
Copy Markdown
Collaborator

Hey @TechGenius-Karan can you please explain better (maybe with a clip of the bug or idk) whats the issue you fixed

@TechGenius-Karan
Copy link
Copy Markdown
Contributor Author

Happy to clarify! Here's a concrete example of what was wrong and what the fix does.

The problem in one sentence: The velocity and acceleration stored in state.velocity / state.acceleration always
pointed purely horizontal — no matter what angle the plane was set to.

Concrete example — 30° incline, ball moving at 5 m/s along the plane:

Before fix:
state.velocity = (5, 0) ← always horizontal, ignores the 30° angle

After fix:
state.velocity = (5·cos30°, 5·sin30°)
= (4.33, 2.5) ← correctly along the inclined direction

Visually:

Before (wrong): After (correct):
↗ plane ↗ plane
→ velocity arrow ↗ velocity arrow
(points flat) (follows the slope)

Why it matters: state.velocity is what gets read when drawing velocity/acceleration vector arrows on screen, and
when other parts of the code ask "how fast is the body moving and in what direction?" With the old code, those
vectors always pointed flat-right regardless of slope — visually wrong and giving incorrect component values to
anything downstream that used them.

The fix (3 lines in stepAlongPlane()):
// Before:
this.state.velocity.set(v, 0);

// After:
this.state.velocity.set(v * Math.cos(angleRad), v * Math.sin(angleRad));
this.state.acceleration.set(a * Math.cos(angleRad), a * Math.sin(angleRad));

Hope this clarifies your doubt better.
@mattqdev

@mattqdev
Copy link
Copy Markdown
Collaborator

Oh yeah all clear now! Was an easy one to understand, I'm sorry I'm so tired I feel dumb

@mattqdev
Copy link
Copy Markdown
Collaborator

Anyway thank you for this!

@mattqdev mattqdev merged commit 96c5b90 into physicshub:main May 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants