I am trying to make a point object in 3D in python, and I have the following code
import numpy as np
class Point3D:
def __init__(self, x, y, z):
self.vector = np.matrix([x, y, z])
self.vector.reshape(3, 1)
def x(self): return self.vector.item((0, 0))
def y(self): return self.vector.item((0, 1))
def z(self): return self.vector.item((0, 2))
I am using numpy to create vertical matrices to eventually use this for a rendering engine. I want to be able to reference the x,y and z of this vector without having to type self.vector.item((0, 0))
for example. I want to be able to do point.x
and get the x value from the vector automatically. I also want to be able to set the values as such: point.x = 5
. Is there any way this possible?
I tried setting them at the start in the init function but then I would have to update it every time. I then made functions to there would only have to be an extra 2 chars, but setting is still not implemented.
Math Magician is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.