Click here to Skip to main content
13,407,374 members (53,742 online)
Rate this:
 
Please Sign up or sign in to vote.
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 7:57am
Comments
SK Genius 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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

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;
  Permalink  
v3
Comments
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!
Rate this: bad
 
good
Please Sign up or sign in to vote.

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!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

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
  Permalink  
Comments
velvet7 11-Jul-11 13:41pm
   
Please check out my comment above.
Rate this: bad
 
good
Please Sign up or sign in to vote.

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.
  Permalink  
Comments
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 ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.180221.1 | Last Updated 3 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100