When the lines overlap the equation system will have infinite solutions so will hold a (0/0) division result. Return new Vector2f(this->point.X + k * this->direction.X,īut what happens if there is no intersection point? What value will hold? Vector2f Line2f::GetPoint(const float& k) Using the parametric equation of the line we can use to get the intersection point: We need to equal both lines equations to find the intersection point: What we want is method that tell us whether they intersect in a point or not and (if they do), give us the intersection point:īool TryGetIntersection(const Line2f& other, Vector2f& intersectionPoint) While trying to compute a 2D line intersection there are three possibilities: Where is the line, a point of the line, an scalar and is the direction vector. To represent a line we will use the vector equation. This number is usually pretty small, like 5 or so.After seeing in my last post that we could compute the intersection of 2 lines in 3D space but with a big error probability (due to floating point limited precision) today we will compute it for 2 dimensions in C/C++ with virtually no error! You'll probably have to set some maximum number of per-frame collisions so that you don't get into some kind of near-infinite-loop situation. In the same frame you'd attempt to move the user's point along this updated velocity vector, doing collision detections along the way. Then in the same frame figure out the desired velocity (in our case we'd do a sliding effect by taking the remaining component of the velocity vector that's parallel to the hit surface). So place the object at the earliest intersection point you detect (but slightly offset in the opposite direction to avoid the floating point errors you mentioned). You might have a certain amount of movement until you hit the wall. So let's say the user is pushing their point (or circle, if you want to give yourself a little more wiggle room with penetration testing) along a surface. For the sake of argument let's say you want to slide along surfaces instead of bouncing off of them. So for a given frame you have a certain amount of velocity you want to account for. Well first off I'm assuming you're doing a kind of "trace" like described here: Whilst I can find a lot of information about collision detection on the web (and on this site) I can find precious little information on collision reaction.ĭoes any one know of any good point line collision reaction tutorials? Or is my approach too flawed/over complicated? This can mean that the solution to one collision inadvertently creates another collision, which is ignored.Īnyway, whatever I try, I am having difficulty with edges, and the point is occasionally able to penetrate the polygons and cross lines, which is undesirable. Attempting to fix one collision by moving the point away from the line (even slightly) can cause it to cross another line (one shape I am dealing with is a star, with sharp corners). Having accepted (maybe) that I cannot always exactly position the point on the line, I tried to move the point away from the line slightly (either along the normal to the line, or along the path vector). Because of this, next frame the path might not intersect the line (because it can start on the other side and move away from it) and the point is effectively allowed to cross the line.įirstly, does the analysis sound correct? Since it is not axis aligned, I think there is always some subtle rounding issue (A float representation of a point on a line might be rounded to a point that is slightly on one side or the other). The problem I am having with this approach (I think) is that, next frame the user may try to cross the line again.Īlthough the point is on the poi, the point may not be exactly on the line. In one frame, I can move the point back to the poi (or only alow it to move as far as the poi), and alter the velocity. Ideally I would like the point to be prevented from moving across the line. The problem I am having is with the reaction. AB is a line, and if it crosses the line segment, a collision has occurred (or will occur) and I am able to work out the point of intersection (poi). For each frame, the point moves from A to B. It is quite straight forward to work out if a collision has occurred. The point moves (it has a velocity, and can be controlled by the user), whilst the lines are strait and stationary. I am trying to program point line segment collision detection and reaction.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |