Updated how the vertices and matrices can be accessed. That is via indices ([x][y]) or just by named properties (like x or y).

This commit is contained in:
2020-07-15 10:48:50 -05:00
parent cbdf666509
commit 813c1f531f
3 changed files with 110 additions and 39 deletions
+46 -14
View File
@@ -1,15 +1,32 @@
class Vector4d:
def __init__(self, x, y, z, w):
self.x = x
self.y = y
self.z = z
self.w = w
class Vector2d:
def __init__(self, x, y):
self.points = [x, y]
class Vector3d:
@property
def x(self):
return self.points[0]
@x.setter
def x(self, value):
self.points[0] = value
@property
def y(self):
return self.points[1]
@y.setter
def y(self, value):
self.points[1] = value
def __getitem__(self, key):
return self.points[key]
def __setitem__(self, key, value):
self.points[key] = value
class Vector3d(Vector2d):
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z
self.points = [x, y, z]
def cross_product(self, vector3d):
# Returns a line that is perpendicular to the parameter
@@ -25,8 +42,23 @@ class Vector3d:
# Returns a scalar that defines how similar two
# vectors are to one another.
return self.x * vector3d.x + self.y * vector3d.y + self.z * vector3d.z
@property
def z(self):
return self.points[2]
class Vector2d:
def __init__(self, x, y):
self.x = x
self.y = y
@z.setter
def z(self, value):
self.points[2] = value
class Vector4d(Vector3d):
def __init__(self, x, y, z, w):
self.points = [x, y, z, w]
@property
def w(self):
return self.points[3]
@w.setter
def w(self, value):
self.points[3] = value