# simple line routine

This topic is 4872 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.

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009713
• ### Who's Online (See full list)

There are no registered users currently online

×