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.

Printable View

- 12-02-2005X PaYnE X
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.

- 12-02-2005ElastoManiac
- 12-02-2005MrWizard
Here is another way of writing a solution to the problem. Use the parametric form of a line.

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;

- 12-02-2005VirtualAce
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. - 12-02-2005X PaYnE X
thanks for the replies, i had a question about what mr wizard said:

Code:`point2d newPos = startPos + (endPos - startPos) * t;`

Code:`int newPos.x = startPos.x + (endPos.x - startPos.x) * t;`

int newPos.y = startPos.y + (endPos.y - startPos.y) * t;

- 12-02-2005X PaYnE X
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