Line Equation

Started by
2 comments, last by Leroy1891 20 years, 3 months ago
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.
Advertisement
ay + bx + c = 0
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!
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
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.

This topic is closed to new replies.

Advertisement