#!/usr/bin/python3 # =================================================================== # Scaling point (x,y,z) coordinates # # x0,y0,z0 original point coordinates # xyzmax maximum x,y,z value allowed # =================================================================== def scale_xyz_coordinates(x0,y0,z0,xyzmax): max = abs(x0) if abs(y0) > max: max = abs(y0) if abs(z0) > max: max = abs(z0) scale_factor = abs(xyzmax) / max x1 = round(x0 * scale_factor) y1 = round(y0 * scale_factor) z1 = round(z0 * scale_factor) ##print() ##print(f'max : {max}') ##print(f'xyzmax : {xyzmax}') ##print(f'scale factor: {scale_factor}') ##print(f'old x={x0} newx={x1}') ##print(f'old y={y0} newx={y1}') ##print(f'old z={z0} newx={z1}') return (x1,y1,z1) # ------------------------------------------------------------------- # ---- main # ------------------------------------------------------------------- if __name__ == '__main__': scale_xyz_coordinates(200,400,100,200) print('------------------------------------') scale_xyz_coordinates(-200,-400,-100,-200) print('------------------------------------') scale_xyz_coordinates(200,500,800,1000) print('------------------------------------') scale_xyz_coordinates(500,1000,2000,1000)