How Can Draw a Line Using the X and Y Coordinates of Two Points

Drawing a line within boundaries from point (x, y) with a given angle

It is possible to solve this problem without trigonometric functions. At first construct parametric representation of given AB ray:

 x = A.X + dx * t
y = A.Y + dy * t
where
dx = B.X - A.X
dy = B.Y - A.Y

The check what edge will be intersected first (with smaller t value):

//potential border positions    
if dx > 0 then
ex = width
else
ex = 0

if dy > 0 then
ey = height
else
ey = 0

//check for horizontal/vertical lines
if dx = 0 then
return cx = A.X, cy = ey

if dy = 0 then
return cy = A.Y, cx = ex


//in general case find parameters of intersection with horizontal and vertical edge
tx = (ex - A.X) / dx
ty = (ey - A.Y) / dy

//and get intersection for smaller parameter value
if tx <= ty then
cx = ex
cy = A.Y + tx * dy
else
cy = ey
cx = A.X + ty * dx

return cx, cy

Results for Width = 400, Height = 300, fixed A point and various B points:

100:100 - 150:100   400: 100
100:100 - 150:150 300: 300
100:100 - 100:150 100: 300
100:100 - 50:150 0: 200
100:100 - 50:100 0: 100
100:100 - 50:50 0: 0
100:100 - 100:50 100: 0
100:100 - 150:50 200: 0

How to draw a line with matplotlib?

As of matplotlib 3.3, you can do this with plt.axline((x1, y1), (x2, y2)).

How to draw a line between two given points in R with plotly?

If you are trying to draw a line between the two coordinates, just use the same pattern you used with the other lines.

add_lines(inherit = F, data = lows, x = ~time, y = ~low, 
name = "Lows, line = list(color = "black"))

Sample Image

Math - Get x & y coordinates at intervals along a line

The Point class built in to Flash has a wonderful set of methods for doing exactly what you want. Define the line using two points and you can use the "interpolate" method to get points further down the line automatically, without any of the trigonometry.

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/geom/Point.html#interpolate()



Related Topics



Leave a reply



Submit