I want to draw a straight line in three-dimensional space to find the intersection with the sphere.

Asked 1 years ago, Updated 1 years ago, 102 views

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()

python python3 matplotlib numpy

2022-09-30 21:33

1 Answers

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?


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.