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"))
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
Import a File from a Subdirectory
Index Out of Bounds Error:Python
Pyqt: Getting Widgets to Resize Automatically in a Qdialog
How to Set Proxy Authentication (User & Password) Using Python + Selenium
Python: Assign Labels to Values in an Array
Pandas - Find Index of Value Anywhere in Dataframe
How to Replace Negative Numbers in Pandas Data Frame by Zero
Django Viewset Has Not Attribute 'Get_Extra_Actions'
How Does the Code Prints 1 2 6 24 as Output and Not 24 6 2 1
How to Remove Commas and Dots of Individual Word in Two Dimensional List
How to Expand Input Buffer Size of Pyserial
Extract Values Between Two Strings in a Text File Using Python
Comparing Digits in an Integer in Python
How to Pivot on Multiple Columns in Spark SQL