96 def get_body(self, origin):
97
98 orientation_np = np.array(self.orientation)
99 scale = np.linalg.norm(orientation_np)
100 normz_orien = orientation_np / scale
101
102 body = pv.Box()
103
104 if(self.body_type ==
'cylinder'):
105 body = pv.Cylinder(center=origin, direction=self.orientation, radius=self.radius1,
106 height=self.height, resolution=self.resolution)
107 elif(self.body_type == 'sphere'):
108 body = pv.Sphere(center=origin, radius=self.radius1, phi_resolution=self.resolution)
109 elif (self.body_type == 'torus'):
110 pyvista_radius = self.radius1 - self.inner_radius
111 body1 = pv.ParametricTorus(ringradius=pyvista_radius, crosssectionradius=self.inner_radius)
112 body2 = pv.Cylinder(center=[0,0,0], direction=[0, 0, 1], radius=pyvista_radius,
113 height=self.inner_radius*2, resolution=self.resolution)
114 roller = [body1, body2]
115 body = pv.MultiBlock(roller).combine()
116
117
118 angles = get_euler_angles_from_vectors(np.array([0., 0., 1.]), normz_orien)
119
120 body.rotate_x(angles[0])
121 body.rotate_y(angles[1])
122 body.rotate_z(angles[2])
123
124 transform_matrix = np.array(
125 [[1, 0, 0, origin[0]], [0, 1, 0, origin[1]], [0, 0, 1, origin[2]], [0, 0, 0, 1]])
126 body.transform(transform_matrix, inplace=True)
127
128 elif(self.body_type == 'plane'):
129 body = pv.Plane(center=origin, direction=self.orientation, i_resolution=self.resolution,
130 j_resolution=self.resolution, i_size=scale, j_size=scale)
131
132 elif(self.body_type == 'cone'):
133 body = get_capped_cone(origin, self.orientation, self.radius1, self.angle, self.height, self.resolution)
134
135
136 elif(self.body_type == 'roller'):
137
138 pyvista_radius = self.radius1 - self.inner_radius
139 body1 = pv.ParametricTorus(ringradius=pyvista_radius, crosssectionradius=self.inner_radius)
140 angles = get_euler_angles_from_vectors(np.array([0., 0., 1.]), normz_orien)
141 body1.rotate_x(angles[0])
142 body1.rotate_y(angles[1])
143 body1.rotate_z(angles[2])
144 transform_matrix = np.array(
145 [[1, 0, 0, origin[0]], [0, 1, 0, origin[1]], [0, 0, 1, origin[2]], [0, 0, 0, 1]])
146 body1.transform(transform_matrix, inplace=True)
147
148
149 slope_a = np.tan(self.angle_a * np.pi / 180)
150 offset_a = (self.inner_radius * slope_a / np.sqrt(1 + slope_a * slope_a)) + self.height / 2
151 new_origin = origin + normz_orien * offset_a
152 cone_rad = pyvista_radius + self.inner_radius / np.sqrt(1 + slope_a * slope_a)
153 body2 = get_capped_cone(new_origin, self.orientation, cone_rad, self.angle_a, self.height, self.resolution)
154
155
156 slope_b = np.tan(self.angle_b * np.pi / 180)
157 offset_b = (self.inner_radius * slope_b / np.sqrt(1 + slope_b * slope_b)) + self.height / 2
158 new_origin = origin - normz_orien * offset_b
159 cone_rad = pyvista_radius + self.inner_radius / np.sqrt(1 + slope_b * slope_b)
160 orientation_flip = normz_orien * -1
161 body3 = get_capped_cone(new_origin, orientation_flip, cone_rad, self.angle_b, self.height, self.resolution)
162 body = pv.MultiBlock([body1, body2, body3]).combine()
163 else:
164 exit("this body type is not supported")
165
166
167 return body
168
169
170
if(!static_cast< bool >(ifstream(param_file)))