Plot a plane that spanned by two vectors in python but raising zero division error

334 views Asked by At

I have two vectors v1 = np.array([-1, 1, 0]) and v2 = np.array([0, 0, 1]) and i want to plot a plane that spanned by these two vectors.

vectors v1 and v2
vectors v1 and v2

import numpy as np
from plotly import graph_objs as go 

v1 = np.array([-1, 1, 0])
v2 = np.array([0, 0, 1])

trace_v1 = go.Scatter3d(x=[0, v1[0]], y=[0, v1[1]], z=[0, v1[2]],mode='lines')
trace_v2 = go.Scatter3d(x=[0, v2[0]], y=[0, v2[1]], z=[0, v2[2]],mode='lines')

xx, yy = np.meshgrid(np.linspace(-1, 1, 10), np.linspace(-1, 1, 10))
cp = np.cross(v1, v2)                    # result is [1, 1, 0] 
zz = (-cp[0]*xx - cp[1]*yy) / cp[2]      # cp[2] is zero and raise an error because of zero division

surf = go.Surface(x=xx, y=yy, z=zz)

fig = go.Figure(data=[trace_v1, trace_v2, surf])
fig.show()

I try to use np.cross() between v1 and v2 for specifying zz but cp[2] is zero and raise an error : divide by zero encountered in true_divide

How should I specify zz ?

0

There are 0 answers