u = np.linspace(0, 2 * np.pi, 100) v = np.linspace(0, np.pi, 100) x_c = 1 * np.outer(np.cos(u), np.sin(v)) y_c = 1 * np.outer(np.sin(u), np.sin(v)) z_c = 1 * np.outer(np.ones(np.size(u)), np.cos(v)) elev = 10.0 rot = 80.0 / 180 * np.pi ax.plot_surface(x_c, y_c, z_c, rstride=4, cstride=4, color='b', linewidth=0, alpha=0.25) ax.view_init(elev=elev, azim=0) in1d = reduce(np.intersect1d, ((U, V, W), (x_c, y_c, z_c))) print(in1d) print('Yes' if in1d else 'No') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show() Closed due to the fact that off-topic participants Kromster , freim , Enikeyschik , andreymal , aleksandr barakin February 4 at 14:18 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, freim, andreymal, aleksandr barakin
- Questions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question. Questions without an explicit description of the problem are useless for other visitors. - Kromster
|
1 answer
Vector? Sphere? These are slightly different concepts, it is unlikely that a vector can cross something.
If we are talking about a segment (segment) of a line, then it is enough to substitute the parametric representation of the segment into the sphere equation and find out if the resulting quadratic equation has solutions on the interval of the parameter t 0..1
X = X0 + t * (X1-X0) и аналогично для Y, Z или X = X0 + t * dx где dx = X1-X0 Substitute this into the sphere equation. If the radius R and the center at the origin:
X^2 + Y^2 + Z^2 = R^2 It turns out the equation
(dx^2+dy^2+dz^2)*t^2 + 2*(X0*dx+Y0*dy+Z0*dz)*t + (X0^2+Y0^2+Z0^2-R^2) = 0 Example:
R=5 P0=(-8,-6,0) P1=(8,6,0) D = (16,12,0) (dx^2+dy^2+dz^2)*t^2 + 2*(X0*dx+Y0*dy+Z0*dz)*t + (X0^2+Y0^2+Z0^2-R^2) = 0 400*t^2 - 400*t + 75 = 0 16*t^2 - 16*t + 3 = 0 D = 256 - 192 = 64 t1 = (16-8)/32 = 1/4 t1 = (16+8)/32 = 3/4 Xi1 = -8 + 16/4 = -4 Yi1 = -6 + 12/4 = -3 Xi2 = -8 + 3*16/4 = 4 Yi2 = -6 + 3*12/4 = 3 (пифагорова тройка) - Implementing what - solving a quadratic equation? - MBo
- The coefficients of the quadratic equation found? - MBo
- Where in the code is the start and end point - point, point2? From them it is necessary to calculate the difference of the type
dx=point2.x-point.xto form an equation. - MBo - With mathematics, there were no problems - to make a quadratic equation. Decide how at school or using
numpy.roots- MBo 4:21 pm - In the answer, if there are roots in the range 0..1, that is, intersections, they can be found by substituting t in the equations for X, Y, Z - MBo
|