ive already tried that method and yes it was way too slow. isnt there a formula for drawing lines? that would probably have what im looking for.
ive already tried that method and yes it was way too slow. isnt there a formula for drawing lines? that would probably have what im looking for.
lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu
Here is another way of writing a solution to the problem. Use the parametric form of a line.
I hope you see what this code is doing. You start at the first point and move t units along the vector direction given by (endPos - startPos). t is a real number in the range of [0.0, 1.0]. It should be quite clear that plugging in 0 for t will yield your start point and 1 will yield the end point. So any fractional value will give you somewhere in between. 0.5 will give you the half way point. Hope this helps you. You can google parametric line form for more information if you need it.Code:// Assuming you have startPos and endPos as the two // points in your line segment // Range of [0.0, 1.0] float t = 0.0f; point2d newPos = startPos + (endPos - startPos) * t;
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
If you notice what Mr. Wizard posted it is essentially linear interpolation.
value=value1+interp_value*(value2-value1);
or
finalpos=startpos+interp_value*(endpos-startpos);
Note that a line though has 2 dimensions so a line is really a bilinear interpolation. You interpolate on X and interpolate on Y to achieve the final point.
Bilinear interpolation essentially will find any point on that line between startpos and endpos using an interp factor of T or as Mr. Wizard was using it, a time factor. But it is still a basic interpolation between A and B.
Graphics cards use this same type of function to filter pixels and create the blotches of color instead of texels as big as your fist when you get close to them. They bilinear interpolate component wise on the horizontal and vertical to achieve the final outcome.
What Shakti posted is basically what you must use if you do not know the endpoint of the line. Like if you want to fire a bullet from point A at point B in 2D you would subtract the x and y components, normalize them, and use those normalized values as your xincrement and yincrement. To interpolate along these
then you would use xincrement and yincrement in a bilinear interpolation to find where a point is a time T or you can integrate over time using xincrement and yincrement to achieve a smooth movement from startpos to endpos.
However since a bilinear interpolation could be quite slow you can also simply find the slope of the line and use that as the T factor in the parametric form of the line.
Last edited by VirtualAce; 12-02-2005 at 04:03 PM.
thanks for the replies, i had a question about what mr wizard said:
is that supposed to be read as:Code:point2d newPos = startPos + (endPos - startPos) * t;
i realize that Bubba tried to explain, but ive never done bilinear interpolation so im kinda lost.Code:int newPos.x = startPos.x + (endPos.x - startPos.x) * t; int newPos.y = startPos.y + (endPos.y - startPos.y) * t;
nevermind, i just read through his post again and understood it.
heres a link to a few similar questions for anyone whos interested: http://www.cc.gatech.edu/gvu/multime...faq_lines.html