3 This script transforms the coordinates in a stl file. We support three modes: scale, translate, or rotate
7 python dafoam_plot3dscale.py scale plot3d_file_input.xyz plot3d_file_output.xyz 2 2 2
8 This will scale the x, y, and z coordinates by a factor of 2
10 python dafoam_plot3dscale.py translate plot3d_file_input.xyz plot3d_file_output.xyz 1 2 3
11 This will translate the x, y, and z coordinates by 1, 2, and 3
13 python dafoam_plot3dscale.py rotate plot3d_file_input.xyz plot3d_file_output.xyz x 10
14 This will rotate the x, y, and z coordinates with respect to the x axis by 10 degree
23 inputFileName = sys.argv[2]
24 outputFileName = sys.argv[3]
27 scaleX = float(sys.argv[4])
28 scaleY = float(sys.argv[5])
29 scaleZ = float(sys.argv[6])
32 "Scaling %s to %s with scaleX: %g scaleY: %g scaleZ: %g ...."
33 % (inputFileName, outputFileName, scaleX, scaleY, scaleZ)
36 myMesh = mesh.Mesh.from_file(inputFileName)
42 myMesh.save(outputFileName)
45 "Scaling %s to %s with scaleX: %g scaleY: %g scaleZ: %g Done!"
46 % (inputFileName, outputFileName, scaleX, scaleY, scaleZ)
48 elif mode ==
"translate":
49 dX = float(sys.argv[4])
50 dY = float(sys.argv[5])
51 dZ = float(sys.argv[6])
54 "Translating %s to %s with dX: %g dY: %g dZ: %g ...."
55 % (inputFileName, outputFileName, dX, dY, dZ)
58 myMesh = mesh.Mesh.from_file(inputFileName)
64 myMesh.save(outputFileName)
67 "Translating %s to %s with dX: %g dT: %g dZ: %g Done!"
68 % (inputFileName, outputFileName, dX, dY, dZ)
70 elif mode ==
"rotate":
71 axis = str(sys.argv[4])
72 deg = float(sys.argv[5])
75 "Rotating %s to %s wrt to the %s axis by %g degree...."
76 % (inputFileName, outputFileName, axis, deg)
85 theta = - deg * np.pi / 180.0
87 myMesh = mesh.Mesh.from_file(inputFileName)
90 myMesh.rotate([1.0, 0.0, 0.0], theta)
92 myMesh.rotate([0.0, 1.0, 0.0], theta)
94 myMesh.rotate([0.0, 0.0, 1.0], theta)
96 print(
"Axis %s not supported! Options are: x, y, or z"%s)
98 myMesh.save(outputFileName)
101 "Rotating %s to %s wrt to the %s axis by %g degree Done!"
102 % (inputFileName, outputFileName, axis, deg)
105 print(
"Mode %s not supported! Options are: scale, translate, or rotate"%s)