# Equation to find endpoints on a line

Printable View

• 12-09-2001
Isometric
Equation to find endpoints on a line
What is the equation to find points on a line? My problem is that I need to draw a line with a variable slope and y intercept. Does anyone have any idea how to figure out the co-ordinates to begin and end the line on. I know the equation y=mx+b (where x and y are any real numbers, m is the slope, and b is the Y intercept) but how can I use that to fine the points to start and end my line on if Im only given m and b?
• 12-09-2001
The V.
Umm, a line HAS no endpoints...

If you wanted to draw a line segment between, say, x = -5 and x = +5, then plug those values in for x to obtain y, and those are the points.
• 12-09-2001
Isometric
Let me clarify...I want to know how I can calculate the coordinates to put into MoveToEx and LineTo functions.How would I calculate where the line goes through the edge of the client area?
• 12-10-2001
adrianxw
It depends on the position of your axes in the client area and what scaling you are using, (i.e. how many pixels per axis unit). More info required I'm afraid.
• 12-10-2001
Isometric
The client area is 510 pixel by 420 picels (fixed). this is devided by 30 to give the grid. The line will extended from one end to the other. I dont need the code tho I just need the formula.
• 12-10-2001
The V.
Figure out the x-value and y-value of each side of the screen.

use the line equation to calculate the x,y pairs which correxpond to:

(xmin, y)
(xmax, y)
(x, ymin)
(x, ymax)

There will only be 2 unique points out of these 4 which are on the screen, these are the points to draw between.
• 12-10-2001
Isometric
so basicaly I should put in into y=mx+b with X being the max or min respectivly?
• 12-10-2001
The V.
Quote:

Originally posted by Isometric
so basicaly I should put in into y=mx+b with X being the max or min respectivly?
that gets you two of the 4 points, the min x and min y.

The other 2 points, you plug into x = (y-b)/m with y = ymin and y = ymax.

Now, of those 4 points, only 2 unique points will be "on the screen" -- these are the 2 points that the line meets the edge of the screen.
• 12-11-2001
novacain
If Width/2 == center point and 0,0 (Width in pixcels)
Scale == spacing of marks on x axis (in pixcels)

then
xMax= Width/(Scale*2)
xMin= -xMax

so

yStart=m*xMin+b
yEnd =m*xMax+b

Giving

MoveToEx(hdc,xMin,yStart,(LPPOINT)NULL);
LineTo(hdc,xMax,yEnd);