Archived

This topic is now archived and is closed to further replies.

Leroy1891

Line Equation

Recommended Posts

Leroy1891    122
Does anyone know how to calculate the points that make up a line? I know how to test if a point is on the line but i want to be able to build a line and can''t seem to do it without gaps and other abnormalities.

Share this post


Link to post
Share on other sites
cmptrgear    306
Depends how you want to do it
There is
y=mx+b
where m is the slope and b is the y-intercept

or you could go the more graphics oriented approach

Pnew=P0+t(P1-P0)
where P0 is the starting point, P1 is the ending point and t is a value between 0 and 1. If t is 0.5 then the equation gives you a point on the line halfway between the two. t can be greater than 1 or less than 0 if you want an infinite line but in graphics we usually work with line segments.

"Give a man a fish and he will eat for a day, drown a man in the water and the fish will eat for a week!

Share this post


Link to post
Share on other sites
SiCrane    11839
If you''re wanting to know how to do pixel plotting for the line, the classic alogorithm is Bresenham''s line algorithm. There''s an article describing it here on gamedev.

Share this post


Link to post
Share on other sites