In [ ]:
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
import plotly.graph_objs as go
init_notebook_mode(connected=True)

In [ ]:
import numpy as np

In [ ]:
z1 = [[6 - i - j for i in range(10)] for j in range(10)]

z2 = [[zij+10 for zij in zi] for zi in z1]
z3 = [[zij-10 for zij in zi] for zi in z1]

iplot([
    dict(z=z1, showscale=False, type='surface'),
    dict(z=z2, showscale=False, opacity=0.9, type='surface'),
    dict(z=z3, showscale=False, opacity=0.9, type='surface')])

In [ ]:
def zCoordinates(a, d): #Weirdly, the mesh has to start from 0 and has to be integer type.
    z = [[(d - a[0]*i - a[1]*j)/a[2] for i in range(10)] for j in range(10)]
    return z

def pointIntersect(n1, d1, n2, d2):
    point = np.linalg.solve([n1[1:], n2[1:]], [d1, d2])
    p = [0, point[0], point[1]]
    return p

In [ ]:
n1 = [2.0, 3.0, -1.0]
d1 = 7.0
z1 = zCoordinates(n1, d1)

n2 = [1.0, 1.0, 1.0]
d2 = 1.0
z2 = zCoordinates(n2, d2)

gradient = np.cross(n1,n2)

point = pointIntersect(n1, d1, n2, d2)

print(gradient, point)

x3 = [point[0] + gradient[0]* t for t in np.linspace(-5, 5, 11)]
y3 = [point[1] + gradient[1]* t for t in np.linspace(-5, 5, 11)]
z3 = [point[2] + gradient[2]* t for t in np.linspace(-5, 5, 11)]

data = [dict(z=z1,
             colorscale='Reds',
             showscale=False,
             type='surface'
            ),
        dict(z=z2,
             colorscale='Blues',
             showscale=False,
             type='surface'),
        go.Scatter3d(x = x3,
                     y = y3,
                     z = z3,
                     mode = 'lines'
                    )
       ]

trace1 = dict(z=z1,
              colorscale='Reds',
              showscale=False,
              type='surface')

trace2 = dict(z=z2,
              colorscale='Blues',
              showscale=False,
              type='surface')

trace3 = go.Scatter3d(x = x3,
                      y = y3,
                      z = z3,
                      mode = 'lines')
data = []
data.append({"name": str('Plane 1'), "data": [trace1]})
data.append({"name": str('Plane 2'), "data": [trace2]})
data.append({"name": str('Line'), "data": [trace3]})

layout = go.Layout(
title="3D Planes Intersection",
xaxis=dict(title='x-axis'),
yaxis=dict(title='y-axis'))

figure = go.Figure(data=[trace1, trace2, trace3], layout=layout)
plot(figure)

In [ ]:
import json

In [ ]:
with open("data_dk.json", 'w') as test_file:
    json.dump(data, test_file, ensure_ascii=False)

In [ ]: