views:

476

answers:

4

if we know the start point and the end point for an line how can you find the all point that line pass it ??

A: 

If you mean points with integer coordinates, you find the delta x and delta y between your start and end points and get the greatest common divisor of the two. Then your points are of the form

(startx + N * deltax / gcd(deltay, deltax), starty + N * deltay / gcd(deltay, deltax))

where N ranges from 0 to gcd(deltay, deltax).

ysth
A: 

say x1,y1 and x2,y2 are points you have then equation of line joining two points will be

y - y1 = (x - x1) * ((y2-y1)/(x2-x1)).

To find every other point substitute x or y and get the other

yesraaj
A: 

Based on how long ago you became a member and the type of question you asked, this sounds like a homework question. I help you anyway but I leave something for thing for you to figure out.

  1. To write a program to do this, you need to know the algebra behind it.
  2. Equation for a straight line: y = mx + b where m is the slope and b is the y-intersect
  3. First find the slope, then find the y-intersect.
  4. Now the tricky part, it's difficult to find ALL points that are on the line. It's however EASY to find all points with either integer x-coordinate or integer y-coordinate that are on the line.
Khnle
+1  A: 

Please go through the URL,

http://cs.unc.edu/~mcmillan/comp136/Lecture6/Lines.html

You will get different type of implementations and select one which is fitting your application.

lakshmanaraj
That article was EXCELLENT! Thanks for sharing it.
Ducain