Jump to content
  • Advertisement
Sign in to follow this  

line surface break thru prevention?

This topic is 4132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i'm trying to change/adapt a physics engine from the FLADE engine (it's verlet physics), and i noticed that to prevent particles/circles from "crossing over" line surfaces, the line surfaces had only one collision face, so that if a particle was near the line surface on the other side, it would be moved back to the collision side. However, I want to make it so that both sides of a line surface are collidable, and i have two ideas in mind, but i don't know how to implement them :( First idea: Somehow calculate whether the particle's current position is on the other side of the line segment than the particle's previous position. Second idea: Find out if the line surface segment touches the line segment formed by the current and previous positions of the particle; this would mean that the particle crossed over the line surface. Does anyone know how to do either of the above calculations? I don't know much of this goemetry stuff.

Share this post


Link to post
Share on other sites
Advertisement
Your second idea is the conventional way of doing things. As for actually doing the 2d line intersection, here's what I found on google:

http://www.ogre3d.org/wiki/index.php/2D_line_intersection

A common way is to take the parametric equation for a point on a line:
Point = Start + t.(End - Start)

The above equation will produce all the points on the line when t is between 0 and 1. (Point, Start and End are vectors. ie. they have an x and y component, t is simply a real number called a scalar)

So, firstly create a parametric equation for your 2 lines; line0 and line1:
Point0 = Start0 + t0.(End0 - Start0)
Point1 = Start1 + t1.(End1 - Start1)

You can then relate the parametric equation for both lines by reasoning thus:
If they intersect, then Point0.xy = Point1.xy.
This leads to the following:
Start0 + t0.(End0 - Start0) = Start1 + t1.(End1 - Start1)
thus,
Start0 - Start1 = t1(End1 - Start1) + t0(Start0 - End0)

Remembering that the above variables are vectors we then get 2 equations:
Start0.x - Start1.x = t1(End1.x - Start1.x) + t0(Start0.x - End0.x)
Start0.y - Start1.y = t1(End1.y - Start1.y) + t0(Start0.y - End0.y)

We now have 2 equations and 2 unknowns. We solve for t0 and t1 by using simulataneous methods; I usually use gaussian elimination (http://en.wikipedia.org/wiki/Gaussian_elimination). Once you have solved for the values of t0 and t1, you can check whether they are in the 0..1 range. If either of them is not in the 0..1 range it means they do not intersect. Also, if we have any divide by zeros during your solving (ie. a zero in the denominator) the 2 lines are likely parallel and do not intersect.

Hope that helps a bit (sorry for the lack of diagrams)

Share this post


Link to post
Share on other sites
Thanks frey, the code at ogre3d.org seems simple enough, but it's not working for me, probably because of some error i made porting the code to the language i use. I'll take a look at the second method later, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!