I am trying to work out how to find the angles labelled in the image. I would then like to be able to plot a line intersecting the y or x-axis with a variable angle, say 20 degrees?
I think finding the angle of intersections first is the bit that could then help me work out how to do the variable bit myself.
import matplotlib.pyplot as plt
f, ax = plt.subplots(figsize=(10, 10))
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
x = np.linspace(-5,5, 100)
plt.plot(x, -1.5*x+20, '-r', label='y=2x+1')
plt.plot(x, 2.5*x+4, '-r', label='y=2x+1')
plt.show()
Edit
Here is an attempt to rearange the formula given in the correct answer.
and my attempt to codify it, but it breaks.
my_angle = 45
gradient = np.arctan**(np.pi * my_angle/180 + np.pi)
Since you already know the slopes of your two lines, you can simply compute the inverse tan of the slopes to get the angles. You can then multiply with 180 / np.pi
to get the values in degrees.
import numpy as np
angle1 = np.arctan(2.5) * 180 / np.pi # angle in degrees
# 68.19859051364818
angle2 = 180 - abs(np.arctan(-1.5) * 180 / np.pi) # angle in degrees
# 123.69006752597979
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.