# simple line routine

This topic is 4962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. Can somebody help me? I need an c++ routine calculates x, y coordinates for line (from x1,y1 to x2,y2). This is simple question, but I don't have solution to this problem. I saw a 1000 examples on net, but all examples was too large and too complicated. I just need an small and fast routine. Pliz help :)

##### Share on other sites
Have you tried to do it yourself?

##### Share on other sites
Well, assuming that you have a variable, t, that tells you which point on the line, it is simple:
x = x1 + t * ( x2 - x1 );
y = y1 + t * ( y2 - y1 );

##### Share on other sites
Yeah I tried to do it myself, but don't know how. I read a tons of artcles as I said, but everything is too complicated (or I just didn't understan it).
It is posible that's because I am programmer not matematician :).
Anyway thanks for your replays, sure I try to implement something on formulas posted above.

##### Share on other sites
The fastest algorithm to draw a line is Bresenham's
Search for Bresenham on google. It uses only integers numbers.

It is infinitly more quick that computing the slope. It is also used in 3D cards accelerators to compute fast the triangles bounds rasterized.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 19
• 15
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015511
×