Issue
I want to plot points, which lie in xy plane. The thing is the points are with their given x, y, and z coordinates. I want a plane, not a 3d object. So the planes would be xy, xz, yz. But others can be exemplified from xy plane. What I am asking is xy plane case.
The example points are with their corresponding normals
point A=(10600, 26.662,-0.420), (Normal) N_A = [0.91, 0.36, 0.21]
point B=(9600, -30.532,-6.208), (Normal) N_B = [0.81, 0.50, -0.30]
point C=(1000, 10.5, -3.72), (Normal) N_C = [-0.83, -0.54, 0.11]
Taking x and y values from these x,y, and z coordinates, how to draw the points in xy plane with their normals and perpendicular lines to the normals? enter image description here
Solution
If you want a projection onto the xy plane, you just need to use the first two coordinates of the points:
A_xy = [A[0], A[1]]
Projection on the xz plane is
A_xz = [A[0], A[2]]
and so on. The projections can be plotted as an arrow or points on the plane.
If you have a vector N = [nx, ny]
in a plane, then the line perpendicular to this vector and going through the point N
is given by:
y(x) = -nx/ny*(x - nx) + ny
which you can plot as a function in variable x. Or, calculate start and end points using this function and plot a straight line between calculated start and end points.
Example:
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import numpy as np
fig, ax = plt.subplots()
arrow_scale = 100
A = [10600, 26.662,-0.420]
N_A = np.array([0.91, 0.36, 0.21])*arrow_scale
B = [9600, -30.532,-6.208]
N_B = np.array([0.81, 0.50, -0.30])*arrow_scale
xmin = min(A[0], B[0]) - 2*arrow_scale
xmax = max(A[0], B[0]) + 2*arrow_scale
ymin = min(A[1], B[1]) - 2*arrow_scale
ymax = max(A[1], B[1]) + 2*arrow_scale
arrow_A = mpatches.FancyArrowPatch((A[0], A[1]), (A[0] + N_A[0], A[1] + N_A[1]), mutation_scale=10)
ax.add_patch(arrow_A)
arrow_B = mpatches.FancyArrowPatch((B[0], B[1]), (B[0] + N_B[0], B[1] + N_B[1]), mutation_scale=10)
ax.add_patch(arrow_B)
x = np.linspace(xmin, xmax, 3)
line_A = -N_A[0]/N_A[1]*(x - A[0]) + A[1]
ax.plot(x, line_A)
line_B = -N_B[0]/N_B[1]*(x - B[0]) + B[1]
ax.plot(x, line_B)
ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
ax.set(aspect=1)
plt.show()
Answered By - Nechoj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.