Source

geoalg / geoalg / plane.py

Full commit
#!/usr/bin/env python
#coding:utf-8
# Author:  mozman
# Purpose: plane
# module belongs to package: geolib.py
# Created: 28.02.2010
# License: GPL

from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import absolute_import

from geoalg import Vec3

class Plane(object):
    def __init__(self, dist=0, vector=(0., 0., 1.)):
        self.nv = Vec3(vector).norm()
        self.d = dist

    def get_x(self, y, z):
        return (self.nv[1]*y + self.nv[2]*z - self.d) / -self.nv[0]
    def get_y(self, x, z):
        return (self.nv[0]*x + self.nv[2]*z - self.d) / -self.nv[1]
    def get_z(self, x, y):
        return (self.nv[0]*x + self.nv[1]*y - self.d) / -self.nv[2]

    @staticmethod
    def from_2vectors(vector1, vector2):
        plane = Plane()
        v1 = Vec3(vector1)
        v2 = Vec3(vector2)
        plane.nv = v1.cross(v2).norm()
        plane.d = v1.dot(v2)
        return plane

    @staticmethod
    def from_3points(p1, p2, p3):
        v1 = Vec3(p1) - Vec3(p2)
        v2 = Vec3(p3) - Vec3(p2)
        return Plane.from_2vectors(v1, v2)