I'd like to find and describe the expression of a straight line to find the intersection of a straight line and a sphere in 3D space from any two points. How should I program it?
Straight lines in 2D could be drawn from the formula.
I think the expression for a straight line in 3D is y=(x-xp)/a-(z-zp)/c)*b-yp
.
import numpy as np
import matplotlib.pyplot asplt
defmain():
x = np.linspace(0,3,4)#x value range(0,1,2,3)
expression for y=x+1# straight line
plt.plot(x,y,"r-")#draw a straight line
plt.show()#Graph View
if__name__=='__main__':
main()
The mpl_toolkits contains a 3D drawing feature called mplot3d.
https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html
How about using this approach to draw a straight line after drawing a 3D sphere using plot_surface
?
© 2024 OneMinuteCode. All rights reserved.