13,735,244 members
See more:
Hello!

As this is a math related problem, and I am really bad at math I ask it from you, so there is a line (0,0) and (0,2).
Now I would like to get all the points within this line.
How could I do this?
Posted 11-Jul-11 6:57am
Anthony Mushrow 11-Jul-11 13:36pm

There are an infinite number of points on a line so you're going to need to clarify what points you're actually after. Do you mean points on a grid that the line passes directly through?
velvet7 11-Jul-11 13:40pm

Yes. So the points would be:(0,0),(0,1),(0,2)
Christian Graus 11-Jul-11 20:23pm

Oh, come on. He's clearly wanting the points that can be plotted in code, and either way, the equation for getting the points would work for any point inbetween.

## Solution 2

Find the slope m=(x1-x2)/(y1-y1) and make a loop of x where y=mx+c (c=0). now get
(x,y) for a range of x. I'm not sure about my equations. please check those are correct or not.

Correct equations, given (x1, y1) (x2, y2):

m = (y1 - y2) / (x1-x2);
c = y1 - x1 * m;

Then, for any given x:

y = mx + c;
v3
Christian Graus 11-Jul-11 20:23pm

Correct. It's worth adding, the 0 for c is because x is initially zero, so if the first point was 3,0, then c would be 3. I can't vote, sorry, or I'd 5 this.
Аslam Iqbal 12-Jul-11 5:12am

I can't remember, maybe you are right. I just tried to give him concept.
velvet7 12-Jul-11 4:10am

Thank you!

## Solution 3

Have a look at this: http://en.wikipedia.org/wiki/Line_drawing_algorithm[^].
It may not be exactly what you are after, but it leads to versions which your PC uses every day!

## Solution 1

Since you didn't specify the domain let me assure you this will be impossible to do since there is an infinite number of points between any two points. If you expected a different answer from this one it may be rooted in the question you posed.

Cheers!

—MRB
velvet7 11-Jul-11 13:41pm

Please check out my comment above.

## Solution 4

Quote:
Find the slope m=(x1-x2)/(y1-y1) and make a loop of x where y=mx+c (c=0). now get
(x,y) for a range of x. I'm not sure about my equations. please check those are correct or not.

Correct equations, given (x1, y1) (x2, y2):

m = (y1 - y2) / (x1-x2);
c = y1 - x1 * m;

Then, for any given x:

y = mx + c;

The above answer works fine for non vertical lines where X stays constant.
If X stays constant as in a straight vertical line, e.g. at every point on the line X = 2 or 3 ....., the above equation will not work.

Also, between any two points on any type of line, there are an infinite amount of points. Therefore, you would have to specify some type of period either on x or y, e.g. loop get every point at x\y = 0.000001 to 666.00001.
Ralf Meier 3-Jan-18 6:36am

Did you realized that this question is nearly 6.5 years old ...
I think this Solution is no more helpful ...

Top Experts
Last 24hrsThis month
 OriginalGriff 292 Richard MacCutchan 260 Patrice T 136 Eric Lynch 113 KarstenK 102
 OriginalGriff 5,284 Richard MacCutchan 1,854 Patrice T 1,377 CPallini 1,179 Dave Kreskowiak 1,120