csci5607/participation/2023-02-15.py

34 lines
667 B
Python

class Point:
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
def __sub__(self, o):
return Point(self.x - o.x, self.y - o.y, self.z - o.z)
def __str__(self):
return f"({self.x}, {self.y}, {self.z})"
def cross(self, o):
x = self.y * o.z - self.z * o.y
y = self.z * o.x - self.x * o.z
z = self.x * o.y - self.y * o.x
return Point(x, y, z)
p0 = Point(1, 1, 0)
p1 = Point(0, 1, 1)
p2 = Point(1, 0, 1)
e1 = p1 - p0
print(e1)
e2 = p2 - p0
print(e2)
n = e1.cross(e2)
print(n)
# Find A, B, C and D
D = -(n.x * p0.x + n.y * p0.y + n.z * p0.z)
print(n.x, n.y, n.z, D)