here is a snippet I made to calculate the local coordinates of the wall wrt to the building storey. I am working with 3D coords as I find it easier, you do not need actually to calculate the cosines of anything, normalizing the reference directions give you the cosines (what called directional cosines).
import numpy as np
norm = np.linalg.norm
z_norm = np.array([0, 0, 1]) # assuming z axis is always towards +Z global?
refDir_ref = x_s = np.array([3, -1, 0]) # _s for space
x_s = x_s / norm(x_s)
y_s = np.cross(z_norm, x_s)
R_s = np.array([x_s, y_s, z_norm]).transpose()
location_ref = wall_loc = np.array([5000, 5000, 0])
wall_glob = R_s.dot(wall_loc)
print('global coordinate of wall wrt to space is = ', wall_glob)
refDir_space = x_b = np.array([-1, 0, 0]) # _b for building storey
x_b = x_b / norm(x_b)
y_b = np.cross(z_norm, x_b)
R_b = np.array([x_b, y_b, z_norm]).transpose()
location_space = space_loc = np.array([1000, 4000, 0])
space_glob = R_b.dot(space_loc)
print('global coordinate of space wrt to building_storey is = ', space_glob)
wall_tot_glob = space_glob + wall_glob
print('global coordinate of wall wrt to building_storey is = ', wall_tot_glob)
wall_tot_loc = R_b.transpose().dot(wall_tot_glob)
print('local coordinate of wall wrt to building_storey is = ', wall_tot_loc)
the output I get is
global coordinate of wall wrt to space is = [6324.55532034 3162.27766017 0. ]
global coordinate of space wrt to building_storey is = [-1000. -4000. 0.]
global coordinate of wall wrt to building_storey is = [5324.55532034 -837.72233983 0. ]
local coordinate of wall wrt to building_storey is = [-5324.55532034 837.72233983 0. ]