Advertisement

Working with planes

Started by March 21, 2003 03:25 PM
5 comments, last by Jederas 21 years, 11 months ago
This problem has been wracking my brain for a while now. I''m working on a collision detection simulation where a sphere drops onto a plane that is at an angle. I''m a bit confused with how to deal with the collision over the course of the simulation. I know I need to check the sphere''s radius against the plane. The problem I''m having is when the sphere is not over the plane''s set location. I guess what I''m asking is: How do I find any given point on a known plane? I read an article on gamedev which described this, but I couldn''t figure out how to implement it. It talked about sphere-intersection points on the plane. I understood the principle, but could not figure a way to implement it. Any help would be a great relief.
just check the distance from the plane to the sphere''s center, if the abs(distance) from center-of-sphere-to-plane is less than radius then the sphere is bisected by the plane (intersection) otherwise it is behind or infront of the plane depending on the sign of the distance. Now if you want the exact position on the sphere that first collides with the plane, it gets a bit more harry, you can do a reverse ray tracing techinque from the intersection point on the plane to sphere. Sorry it''s been a while since i did this stuff so i cant remember the specifics.
Advertisement
It might help to know how to find the distance of a point from a plane. You can find a displacement vector from any point on the plane to the point of interest. That is the hypotheneous of a right triangle. So the distance is the cosine of the angle between that vector and a vector othogonal (perpendicular) to the plane times the magnitude (length) of the displacement vector. The dot product is A.B=|A||B|cos(t) where t is the angle between A and B and |A| is the magnitude of A. So if A is your displacement vector and B is an orthogonal vector with a magnitude of 1 then A.B is the distance from the plane. In the equation A*x+B*y+C*z=D the vector (A,B,C) is orthogonal to the plane, i.e. (A,B,C).(x,y,z)=D.
Keys to success: Ability, ambition and opportunity.
So the displacement vector would be say, the location of the sphere? Or perhaps the location of the sphere localized to the plane? Say my plane is defined by 4 vertices and a normal, and the sphere is defined by a location point, a radius, and a velocity vector. Gravity is applied to the velocity vector. The plane's vertices are arranged so they form a 45 degree angle along the x axis. I'm checking the distance of the sphere against the center point in the plane (0,0,0). This works at first, but after the first impact, the ball bounces at an angle, causing it to come down over a different area of the plane each time. I guess I can't seem to figure out how find that point on the plane. The ball keeps bouncing, but it's as if it's bouncing off of a stationary sphere, as after a few bounces, it rolls off the side.

if(GetDistance(sphere.loc, dick) < (sphere.radius))
{

sphere.Veloc.Setv(CollisionResponse(sphere.Veloc, d[0].normal));
}




[edited by - Jederas on March 21, 2003 6:43:26 PM]
Is your plane really a plane, or is it a quadrilatera? A plane is infinite; it doesn''t have vertices. Your vertices would be simply some points among the infinity of points in the plane. If this is the case, then your vector "relative" to the plane would be v = Sphere_Center - A_Point_On_The_Plane. Then, the distance is d = v Dot Plane_Normal / Length(Plane_Normal)².

If you don''T know about the dot product, make a Google search.

Cédric
The displacement is from any of the vertices to the center of the sphere. The distance for the actual sphere is that distance minus the radius. For actual collision detection the center of the sphere is a function of time. So you have p(t)=p0+v*t where p0 is the position at time zero, normally the start of the frame, and v is the velocity. So when (p0+v*t).n=r the sphere is just coming in contact with the plane. (p0+v*t).n=p0.n+v.n*t so t=(r-(p0.n))/(v.n). If you plug that value back into p(t) you get the position of the center. p(t)-r*n is the point of contact. The distance is what I call a directed distance. One one side of the plane it is positive, the side the normal points toward, and on the other it is negative where a distance is strictly positive. You know where the center is and want to find the point of contact so you subtract to go from the center to the plane rather than from the plane to the center.

With more complex motion you just approximate things with straight lines. You calculate an average velocity and use it as your velocity during the entire frame. Most often you just use the average of the starting and ending velocity. With constant acceleration that is exactly right for calculating the position at the end of the frame. It isn''t quite exactly right for finding the time of collision. Your distance from the plane as a function of time is a quadradic not a linear function. Generally it is such a small differance that no one cares. Even if your accelerate was time dependant rather than constant it is a trivial differance between the straight line approximation and the real deal. The main thing you have to avoid is extrapolation. Over a 30th of a second it is a trivial differance, but over 30 seconds it isn''t. So you just use it to calculate if a collision occured during a frame.

I don''t know how you are doing your reflections, i.e. bounces. All that takes is reversing the orthogonal component of the velocity, i.e. parallel to the normal. The component of the velocity othogonal to the plane is vo=(n.v)*n and the component parallel is v-vo. So v''=(v-vo)-(n.v)*n=v-2*(n.v)*n. If you use 2 then it is a perfect bounce, i.e. you bounce just as high. If it is less than 2 then it is dampened, i.e. you don''t bounce as high. Needless to say if it is greater than 2 you bounce higher and higher. If you dampen it you may occasionally run into situations where an object sets there and vibrates. That is mainly a roundoff error that keeps it from reaching a stable position. If that happens you either updating the object or move it to a stable position. An example of how to catch it is on a bounce checking that the orthogonal component has a minimum magnitude. If not then you set the orthogonal component to zero and position the object so it just touchs the surface, i.e. no bounces of less than a certain height.
Keys to success: Ability, ambition and opportunity.
Advertisement
Cedric, in this case the plane is actually a plane, although I am representing it on the screen as a quad.

This topic is closed to new replies.

Advertisement