Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:31:59+00:00 2026-05-16T15:31:59+00:00

Does anyone know a very simple physics engine, or just a set of basic

  • 0

Does anyone know a very simple physics engine, or just a set of basic functions that could complete these tasks: Simple point, line, and rectangle collision detection? I looked at Box2D but it is way too advanced for what I am making. I just need some simple code. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:32:00+00:00Added an answer on May 16, 2026 at 3:32 pm

    Here’s my shot at point/line collision detection. The important thing is to avoid trig functions, divisions, and other expensive operations so as not to slow things down too much.

    As GMan’s comment notes, you need to bear in mind that the point will be moving. So you’ll have the current position of the point (let’s call it A) and the possible new position of the point (B). You need to find out if, when the point moves from A to B, it would collide with a line.

    Let’s call the start and end points of the line C and D. A collision will occur only if the lines AB and CD intersect.

    Let’s describe the line AB using the standard equation Ux + Vy + W = 0. After some algebra, the equation comes out as:

    (ay - by) x + (bx - ax) y + ax by - bx ay = 0
    

    We can describe the line CD in terms of a parameter t and constants X Y U V:

    x = X + Ut
    y = Y + Vt
    

    It’s helpful if we set t=0 at point C, and t=1 at point D. By considering t=0 we can work out X and Y. And by considering t=1 we can work out U and V. This gives

    x = cx + (dx - cx) t
    y = cy + (dy - cy) t
    

    To find the intersection point of the two lines, substitute these into the equation we found for AB, which gives

    (ay - by) (cx + (dx - cx) t) + (bx - ax) (cy + (dy - cy) t) + ax by - bx ay = 0
    

    This reduces to

    t = (ax by - bx ay + bx cy - cx by + cx ay - ax cy) / q
    

    where q = (ay - by)(cx - dx) - (ax - bx)(cy - dy)

    • If q is zero, the lines are parallel and do not meet.
    • If 0 < t < 1 then the line extrapolated from AB intersects CD.

    But we still don’t know that this intersection is actually between the points A and B. So we need to repeat all the previous steps, swapping AB and CD, and writing the line AB in terms of a parameter s. This gives:

    s = (cx dy - dx cy + dx ay - ax dy + ax cy - cx ay) / q
    
    • If 0 < s < 1 then the line extrapolated from CD intersects AB.

    That’s it. So in your code you start by calculating q. If q is zero then the lines are parallel. Otherwise, go on to calculate t and s. If 0 < t < 1 and 0 < s < 1 then a collision is about to happen. To find the location of the collision, substitute t or s back into the original equations for CD.

    For extra speed you can remove the divisions by q – it’s possible to just check whether the top half of each fraction is in the correct range, and then each check should only need 10 multiplication operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anyone know a php templating system that is very simple, something like almost
Does anyone know of some (very) simple tutorials on line on the WCF? Basically
Does anyone know of a simple tutorial that provides a step by step guide
Does anyone know why this very simple jquery animation works perfectly in some browsers
does anyone know how purevolume.com gets their rounded corners? its very interesting and cross
Does anyone know of any websites, or (preferably) downloadable packages that you can use
Does anyone know of a base class that can be used to serve up
I have question that seems very simple, but I just can't get it right.
Does anyone know of or can anyone please produce a simple example of Django's
all i need is a very simple auto complete that suggests words that have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.