position of points on a line?
I want to get the position of the points which are on a drawed line. Because i want to collide objects with the line. Start and end points are known. So what is the formula?
Thanks...
use the formula y = mx + b, where b is the starting y-position(lower y coordinate) and where m is
y2 - y1
-------
x2 - x1
Then, plugin the x value and your y is the corresponding height on the line.
y2 - y1
-------
x2 - x1
Then, plugin the x value and your y is the corresponding height on the line.
Quote:Original post by AdamGLI have to disagree with this advice, for the following reasons:
use the formula y = mx + b...
1. There's really no reason (that I can think of at least) to express intersection tests involving linear components in terms of sampled points. The implicit or parametric form should be preferred; either of these will be both faster and more accurate, generally speaking.
2. The y = mx + b formula is only directly applicable in 2D. Although one might surmise that this is a 2D problem from the wording of the OP's post, this was not actually specified.
3. Finally, the explicit form for 2D lines is generally a poor choice for games and graphics applications. It's taught in algebra because it's a classic example of a linear equation and is easy to graph and visualize. However, unlike the implicit and parametric forms it cannot represent lines with arbitrary orientations in a stable and uniform manner, and therefore is usually of little use in the given context.
You are probably better with the parametric form of the line, since there isn't a divide by zero problem if x2 and x1 are the same in the previous formula (and that is 2d only anyway).
If vS, vE are the position vectors of the start and end, then the equation of the line segment from vS to vE is
vs + t(vE - vS)
where t is in the range 0 to 1. This can be multiplied out to get
(1-t)vS + t(vE)
If vS, vE are the position vectors of the start and end, then the equation of the line segment from vS to vE is
vs + t(vE - vS)
where t is in the range 0 to 1. This can be multiplied out to get
(1-t)vS + t(vE)
Quote:Original post by jyk
Quote:
the explicit form for 2D lines is generally a poor choice for games and graphics applications.
true but i really need it. I only want a range for the position of points.
Quote:Original post by uralkemalWhy? Practically speaking, anything you can do with the explicit form you can do with the implicit or parametric form as well (unless there's something I'm overlooking), and with greater generality and robustness.
true but i really need it.
I'll say once again that if this is for collision detection purposes, representing the linear component as a set of discrete points is probably not the best approach. However, if for some reason you really want to do this, you can compute the points quite easily using the parametric form (see Paradigm Shifter's post, above).
Quote:Original post by jykQuote:Original post by uralkemalWhy?
true but i really need it.
Yesterday i found a game. I wanna show you the game. This is not the game i want to do. But similar. You can download: http://nichtnormal.com/daten/learn2fly.zip
It looks like what you're really looking to do is collide segments (the line between the previous position and the present position for your falling object, and the line for the bounce object). Colliding single points against a line isn't going to work.
I can't find any good references to point you to, but I imagine someone else on this board can show you some sample code for segment-segment collision.
I can't find any good references to point you to, but I imagine someone else on this board can show you some sample code for segment-segment collision.
Quote:Original post by uralkemalDon't have time to look at the game atm, but I think you may be missing the point here. I believe you when you say you want to detect intersections with a line segment, but what I and others are trying to tell you is that a) representing the segment as a set of discrete points is not the way to go, and b) y = mx + b is not a useful representation in this context.Quote:Original post by jykQuote:Original post by uralkemalWhy?
true but i really need it.
Yesterday i found a game. I wanna show you the game. This is not the game i want to do. But similar. You can download: http://nichtnormal.com/daten/learn2fly.zip
Here is the first hit from a Google search for 'intersection of lines'. Searching for that and similar phrases should turn up plenty of useful references.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement