finding the second coordinate

A

Ashutosh Iddya

HI,

How do you find the other endpoint of a line given one endpoint and the
slope of the line.

Also how do you display the coordinate on the computer screen knowing
that the Y axis (of the raster display) runs in the reverse direction of
a normal graph.


ex: given two points
x1 = 100
y1 = 600

and given an angle
45 degrees ie the slope(m)of the line is 1
and given the distance of 206 units
how do I find x2 and y2(the other endpoint of the line)?

how do i display it on the computer screen.

thanks,
Ashutosh
 
G

Gordon Beaton

How do you find the other endpoint of a line given one endpoint and
the slope of the line.

For a given starting point and slope, there are infinitely many line
segments with different lengths. Which one of them do you mean? You
need more information.

If you know the slope, then you can find any point on the line by
multiplying any X coordinate with the slope to get the corresponding Y
coodinate, then shifting both values by the offsets of your starting
point.

This becomes obvious when you realize that the slope is simply the
ratio of change in Y to X along any section of the line.

/gordon
 
M

Marco Schmidt

Ashutosh Iddya:
How do you find the other endpoint of a line given one endpoint and the
slope of the line. [...]
how do I find x2 and y2(the other endpoint of the line)?

Please do not multi-post:
<http://www.yoda.arachsys.com/java/newsgroups.html>.

This question is not about Java. It is more likely to be answered in
comp.graphics.algorithms.
how do i display it on the computer screen.

Get a Graphics object for the component you want to draw on. Transform
the coordinates if necessary. Then call drawLine with your
coordinates.

Regards,
Marco
 
K

Knute Johnson

Ashutosh said:
HI,

How do you find the other endpoint of a line given one endpoint and the
slope of the line.

Also how do you display the coordinate on the computer screen knowing
that the Y axis (of the raster display) runs in the reverse direction of
a normal graph.


ex: given two points
x1 = 100
y1 = 600

and given an angle
45 degrees ie the slope(m)of the line is 1
and given the distance of 206 units
how do I find x2 and y2(the other endpoint of the line)?

how do i display it on the computer screen.

thanks,
Ashutosh

deltaX = radius * cos alpha
deltaY = radius * sin alpha

x2 = x1 + deltaX
y2 = y1 + deltaY

cos 45 degrees = .70711
sin 45 degrees = .70711

deltaX = 206 * .70711 = 145.66
deltaY is the same

x2 = 100 + 145 = 245
y2 = 600 + 145 = 745

Normal geometric coordinate systems put 0,0 in the lower left corner.
Computer displays put 0,0 in the upper left corner. To convert from
geometric coordinates to computer display coordinates, subtract the y
coordinate from the height of the display.

computerY = displayHeight - geometricY

Remember too that all the java Math methods use radians and that
geometric angles are measured counterclockwise from the horizontal while
map angles are measured clockwise from the vertical. Your example above
works out because you used 45 degrees which turns out to be the same
angle in either system.
 
B

Brad BARCLAY

Knute said:
Normal geometric coordinate systems put 0,0 in the lower left corner.
Computer displays put 0,0 in the upper left corner.

Beware generalities. While Java and windows use an upper-left origin,
this is not generally true for all computer display systems.

OS/2, for example, uses the lower-left corner as the display origin (as
it should be, IMO).

Brad BARCLAY
 
K

Knute Johnson

Brad said:
Beware generalities. While Java and windows use an upper-left
origin, this is not generally true for all computer display systems.

OS/2, for example, uses the lower-left corner as the display origin
(as it should be, IMO).

Brad BARCLAY

I should have said Winblows displays.

I just de-commissioned my last running OS/2 installation. It had been
running for four years. The original was installed in 1994 and went
through several upgrades. The most bullet proof operating system I've
ever used. It's too bad that IBM is giving up on it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,294
Latest member
HollieYork

Latest Threads

Top