Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a plane with 3 points, and plot it in 3D? [closed]

I have 3 points in 3D space and I want to define a plane passing through those points in 3D.

      X       Y       Z
0   0.65612 0.53440 0.24175
1   0.62279 0.51946 0.25744
2   0.61216 0.53959 0.26394

Also I need to plot that in 3D space.

like image 463
Upriser Avatar asked Dec 10 '18 02:12

Upriser


1 Answers

You define a plane vectorially with a normal and a point. To find the normal, you calculate the cross product of two of the vectors defined by the three points.

Then you use this normal and one of the points to place the plane in space.

Using matplotlib:

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

points = [[0.65612, 0.53440, 0.24175],
           [0.62279, 0.51946, 0.25744],
           [0.61216, 0.53959, 0.26394]]

p0, p1, p2 = points
x0, y0, z0 = p0
x1, y1, z1 = p1
x2, y2, z2 = p2

ux, uy, uz = u = [x1-x0, y1-y0, z1-z0]
vx, vy, vz = v = [x2-x0, y2-y0, z2-z0]

u_cross_v = [uy*vz-uz*vy, uz*vx-ux*vz, ux*vy-uy*vx]

point  = np.array(p0)
normal = np.array(u_cross_v)

d = -point.dot(normal)

xx, yy = np.meshgrid(range(10), range(10))

z = (-normal[0] * xx - normal[1] * yy - d) * 1. / normal[2]

# plot the surface
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()

enter image description here

other useful answers:
Matplotlib - Plot a plane and points in 3D simultaneously
Plot a plane based on a normal vector and a point in Matlab or matplotlib

like image 180
Reblochon Masque Avatar answered Oct 25 '22 22:10

Reblochon Masque