I am using Python3.9.
There are six functions and I want to process 7 times while preventing the same function from repeating twice.
I want to find the coordinates of the mirror image when an arbitrary target coordinate point is reflected 7 times by 6 walls (including ceiling/floor) in a rectangular 3D space. The functions to be processed are def mirror 1 to 6 in the sample code below.
Could anyone tell me How can I code this?
#initial conditions
#room dimensions
xwide = 20
ywide = 15
zwide = 5
#arbitrary coordinates
target = np.array([2, 2, 2])
#Reflection in the y direction on the wall through the origin
xzmirror = np.array([[1, 0, 0], [0, -1, 0], [0, 0, 1]])
#Reflection in the z direction on the wall through the origin
xymirror = np.array([[1, 0, 0], [0, 1, 0], [0, 0, -1]])
#Reflection in the x direction on the wall through the origin
yzmirror = np.array([[-1, 0, 0], [0, 1, 0], [0, 0, 1]])
#prepare normal vector
xn = np.array([-1, 0, 0])
yn = np.array([0, -1, 0])
zn = np.array([0, 0, -1])
#functions to find the mirrored coordinates of a reflection
def mirror1(a):
x0_mir1 = np.dot(a, yzmirror)
return x0_mir1
def mirror2(a):
y0_mir1 = np.dot(a, xzmirror)
return y0_mir1
def mirror3(a):
z0_mir1 = np.dot(a, xymirror)
return z0_mir1
def mirror4(a):
x1_mir1 = a - (2 * (np.dot(a, xn) + xwide)) * xn
return x1_mir1
def mirror5(a):
y1_mir1 = a - (2 * (np.dot(a, yn) + ywide)) * yn
return y1_mir1
def mirror6(a):
z1_mir1 = a - (2 * (np.dot(a, zn) + zwide)) * zn
return z1_mir1