Jump to content
  • Advertisement

Archived

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

Leroy1891

Line Equation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
Guest Anonymous Poster
ay + bx + c = 0

Share this post


Link to post
Share on other sites
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
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!