def contour(self, full_contour=False): p0 = vm.Point2D(0, 0) vectors = [ vm.Vector2D(self.rivet_diameter / 2, 0), vm.Vector2D(self.head_diameter / 2 - self.rivet_diameter / 2, 0), vm.Vector2D(0, self.head_length), vm.Vector2D(-self.head_diameter, 0), vm.Vector2D(0, -self.head_length), vm.Vector2D(self.head_diameter / 2 - self.rivet_diameter / 2, 0), vm.Vector2D(0, -self.rivet_length), vm.Vector2D(self.rivet_diameter, 0), vm.Vector2D(0, self.rivet_length), ] points = [] p_init = p0 for v in vectors: p1 = p_init.translation(v, copy=True) points.append(p1) p_init = p1 c = p2d.ClosedRoundedLineSegments2D(points, {}) if full_contour: return vm.wires.Contour2D(c.primitives) else: line = vm.edges.Line2D( p0, p0.translation(vm.Vector2D(0, -self.rivet_length), copy=True)) contour = vm.wires.Contour2D(c.primitives) return contour.cut_by_line(line)[0]
def contour(self): p0 = vm.Point2D(-self.length / 2, -self.height / 2) p1 = vm.Point2D(-self.length / 2, self.height / 2) p2 = vm.Point2D(self.length / 2, self.height / 2) p3 = vm.Point2D(self.length / 2, -self.height / 2) b1 = p2d.ClosedRoundedLineSegments2D([p0, p1, p2, p3], {}) return vm.wires.Contour2D(b1.primitives)
def contour(self): points = [ vm.Point2D(0, 0), vm.Point2D(0, 1), vm.Point2D(1, 1), vm.Point2D(1, 0) ] crls = p2d.ClosedRoundedLineSegments2D(points=points, radius={}) return vm.wires.Contour2D(crls.primitives)
def chest_contour(self, origin=vm.O2D, chest_angle=0.): p1 = origin + vm.Point2D(0.8 * self.chest_width, 0.) p2 = origin + vm.Point2D(self.chest_width, self.sitting_shoulder_height) p3 = origin + vm.Point2D(0, self.sitting_shoulder_height) p4 = origin + vm.Point2D(0, 0.) contour = p2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4], {1: 0.3 * self.chest_width}) return contour.rotation(origin, chest_angle)
def upper_leg_contour(self, upper_leg_angle: float, origin=vm.O2D): p1 = origin p2 = origin + vm.Point2D(self.upper_leg_length, 0.) p3 = origin + vm.Point2D(self.upper_leg_length, self.upper_leg_width) p4 = origin + vm.Point2D(0., self.upper_leg_width) contour = p2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4], { 1: 0.3 * self.upper_leg_width, 2: 0.3 * self.upper_leg_width }) return contour.rotation(origin, upper_leg_angle)
def backrest_contour(self): backrest_p1 = vm.O2D backrest_p4 = -self.backrest_base_width * vm.X2D backrest_p2 = self.backrest_height * vm.Y2D.copy().rotation( vm.O2D, self.backrest_angle) backrest_p3 = backrest_p2 - self.backrest_top_width * vm.X2D backrest_points = [backrest_p1, backrest_p2, backrest_p3, backrest_p4] backrest_contour = p2d.ClosedRoundedLineSegments2D( backrest_points, { 1: 0.04, 2: 0.01 }) return backrest_contour
def cushion_contour(self): cushion_p1 = vm.O2D cushion_p2 = self.cushion_length * vm.X2D.rotation( vm.O2D, self.cushion_angle) cushion_p3 = cushion_p2 - vm.Y2D * 0.2 cushion_p5 = cushion_p1 - vm.X2D * self.backrest_base_width cushion_p4 = vm.Point2D(cushion_p5[0], cushion_p3[1]) cushion_points = [ cushion_p1, cushion_p2, cushion_p3, cushion_p4, cushion_p5 ] cushion_contour = p2d.ClosedRoundedLineSegments2D( cushion_points, {1: 0.05}) return cushion_contour
def headrest_contour(self): backrest_p2 = self.backrest_height * vm.Y2D.copy().rotation( vm.O2D, self.backrest_angle) headrest_p1 = backrest_p2 + 0.15 * self.headrest_height * vm.Y2D headrest_p2 = backrest_p2 + self.headrest_height * vm.Y2D headrest_p3 = headrest_p2 - self.backrest_top_width * vm.X2D headrest_p4 = headrest_p1 - self.backrest_top_width * vm.X2D headrest_points = [headrest_p1, headrest_p2, headrest_p3, headrest_p4] headrest_contour = p2d.ClosedRoundedLineSegments2D( headrest_points, { 1: 0.04, 2: 0.02 }) return headrest_contour
def lower_arm_contour(self, elbow_postion: vm.Point2D, lower_arm_angle: float): p1 = elbow_postion + vm.Point2D(0., -0.5 * self.lower_arm_width) p2 = elbow_postion + vm.Point2D(self.elbow_grip_center_length, -0.5 * self.lower_arm_width) p3 = elbow_postion + vm.Point2D(self.elbow_grip_center_length, 0.5 * self.lower_arm_width) p4 = elbow_postion + vm.Point2D(0., 0.5 * self.lower_arm_width) contour = p2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4], { 1: 0.3 * self.lower_arm_width, 2: 0.3 * self.lower_arm_width }) return contour.rotation(elbow_postion, lower_arm_angle)
def lower_leg_contour(self, knee_postion: vm.Point2D, lower_leg_angle: float): # width = 0.25*self.lower_leg_length p1 = knee_postion + vm.Point2D(-0.5 * self.lower_leg_width, 0.) p2 = knee_postion + vm.Point2D(-0.5 * self.lower_leg_width, -self.lower_leg_length) p3 = knee_postion + vm.Point2D(0.5 * self.lower_leg_width, -self.lower_leg_length) p4 = knee_postion + vm.Point2D(0.5 * self.lower_leg_width, 0.) contour = p2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4], { 1: 0.3 * self.lower_leg_width, 2: 0.3 * self.lower_leg_width }) return contour.rotation(knee_postion, lower_leg_angle)
def upper_arm_contour(self, shoulder_position: vm.Point2D, upper_arm_angle: float): p1 = shoulder_position + vm.Point2D(-0.5 * self.upper_arm_width, 0.) p2 = shoulder_position + vm.Point2D(-0.5 * self.upper_arm_width, -self.shoulder_elbow_length) p3 = shoulder_position + vm.Point2D( 0.5 * self.upper_arm_width, -self.shoulder_elbow_length, ) p4 = shoulder_position + vm.Point2D(0.5 * self.upper_arm_width, 0.) contour = p2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4], { 1: 0.3 * self.upper_arm_width, 2: 0.3 * self.upper_arm_width }) return contour.rotation(shoulder_position, upper_arm_angle)
def head_contour(self, position): p1 = position + vm.Point2D(-0.5 * self.head_width, -0.3 * self.head_height) p2 = position + vm.Point2D(-0.5 * self.head_width, 0.5 * self.head_height) p3 = position + vm.Point2D(0.3 * self.head_width, 0.5 * self.head_height) p4 = position + vm.Point2D(0.7 * self.head_width, 0.15 * self.head_height) p5 = position + vm.Point2D(0.2 * self.head_width, -0.3 * self.head_height) contour = p2d.ClosedRoundedLineSegments2D( [p1, p2, p3, p4, p5], { 1: 0.3 * self.head_width, 2: 0.6 * self.head_width, 3: 0.1 * self.head_width }) return contour
p7 = vm.Point2D(3, 0.4) p8 = vm.Point2D(3.5, 0.2) rl2D_o = primitives2d.OpenedRoundedLineSegments2D( [p0, p1, p2, p3, p4, p5, p6, p7, p8], {}, # {2:0.3, 4:0.1, 3:0.1}, adapt_radius=True) rl2D_o2 = rl2D_o.offset_lines([2], -1.25) ax = rl2D_o.plot() rl2D_o2.plot(ax=ax) rl2D_c = primitives2d.ClosedRoundedLineSegments2D( [p0, p1, p2, p3, p4, p5, p6, p7, p8], {}, # {0:1, 1:0.05, 2:0.05, 3:1}, adapt_radius=True) rl2D_c2 = rl2D_c.offset_lines([2], 0.2) ax2 = rl2D_c.plot() rl2D_c2.plot(ax=ax2) com = rl2D_c2.center_of_mass() cut_line = vm.edges.Line2D(com, com + vm.Point2D.random(-1, 1, 0, 1)) ax3 = rl2D_c2.plot() cut_line.plot(ax=ax3, color='red') com.plot(color='b', ax=ax3) cutted_contour1, cutted_contour2 = rl2D_c2.cut_by_line(cut_line) # for c in cutted_contours:
l = 0.05 p1 = v * l p2 = p1 + l * u p3 = p2 - 2 * l * v p4 = p3 + l * u p5 = p4 + 2 * l * u + 3 * l * v p6 = p5 + l * u p7 = p6 - 4 * l * v + l * v p8 = p7 - l * u p9 = 0.5 * (p5 + p6) - l * v p10 = p4 - l * v p11 = p1 - 3 * l * v contour = p2d.ClosedRoundedLineSegments2D( [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11], {3: 0.3 * l}) ax = contour.plot(ax=ax1) line = edges.Line2D(vm.O2D, u) line2 = edges.Line2D(0.3 * v, u + 0.3 * v) line.plot(ax=ax1, color='b') line2.plot(ax=ax1, color='g') split_contours1 = contour.cut_by_line(line) for c in split_contours1: c.plot(ax=ax2, color='b') ax2.set_title('{} splitted contours'.format(len(split_contours1))) split_contours2 = contour.cut_by_line(line2) for c in split_contours2:
p6 = vm.Point2D((3, 2)) p7 = vm.Point2D((3, 0)) l1 = p2d.OpenedRoundedLineSegments2D([p7, p1, p2], {}) l2 = vm.Arc2D(p2, vm.Point2D((math.sqrt(2) / 2, 3 + math.sqrt(2) / 2)), p3) l3 = p2d.OpenedRoundedLineSegments2D([p3, p4, p5, p6], {}, adapt_radius=True) l4 = vm.Arc2D(p6, vm.Point2D((4, 1)), p7) #l4=vm.Arc2D(p7, vm.Point2D((4, 1)), p6) c1 = vm.Contour2D([l1, l2, l3, l4]) p8 = vm.Point2D((1, 1)) p9 = vm.Point2D((2, 1)) p10 = vm.Point2D((2, 2)) p11 = vm.Point2D((1, 2)) #inner=vm.Circle2D(vm.Point2D((2,2)), 0.5) inner = p2d.ClosedRoundedLineSegments2D([p8, p9, p10, p11], {}) c2 = vm.Contour2D([inner]) #ax = l1.MPLPlot() #l2.MPLPlot(ax=ax) #l3.MPLPlot(ax=ax) #l4.MPLPlot(ax=ax) profile = p3d.ExtrudedProfile(vm.o3D, vm.x3D, vm.y3D, c1, [c2], vm.Vector3D((0, 0, 1))) profile.MPLPlot() model = vm.VolumeModel([profile]) model.BabylonShow() #%%
import volmdlr.primitives3d as primitives3d import volmdlr.primitives2d as primitives2d p1 = vm.Point2D(0, 0) p2 = vm.Point2D(0.1, 0.) p3 = vm.Point2D(0.1, 0.2) p4 = vm.Point2D(0.05, 0.1) p5 = vm.Point2D(0., 0.21) p6 = vm.Point2D(0.05, 0.05) p7 = vm.Point2D(0.06, 0.05) p8 = vm.Point2D(0.04, 0.07) radius = {0: 0.01, 2: 0.01, 3: 0.015} outer_profile = primitives2d.ClosedRoundedLineSegments2D([p1, p2, p3, p4, p5], radius) l1 = edges.LineSegment2D(p6, p7) l2 = edges.LineSegment2D(p7, p8) l3 = edges.LineSegment2D(p8, p6) c2 = wires.Contour2D([l1, l2, l3]) profile = primitives3d.ExtrudedProfile(vm.O3D, vm.Y3D, vm.Z3D, outer_profile, [c2], vm.X3D * 0.1, name='extrusion') model = vm.core.VolumeModel([profile]) model.babylonjs()
screw_holes_diameter = 0.006 screw_holes_clearance = 0.003 n_screws = 25 p1 = vm.Point2D(0, 0) p2 = vm.Point2D(0.3, 0) p3 = vm.Point2D(0.33, 0.22) p4 = vm.Point2D(0.2, 0.08) p5 = vm.Point2D(0.16, 0.18) p6 = vm.Point2D(0.05, 0.20) inner_contour = primitives2d.ClosedRoundedLineSegments2D( [p1, p2, p3, p4, p5, p6], { 0: 0.01, 1: 0.01, 2: 0.015, 3: 0.020, 4: 0.012, 5: 0.008 }, adapt_radius=True) outer_contour = inner_contour.offset(-thickness) a = inner_contour.plot() outer_contour.plot(a) sides = primitives3d.ExtrudedProfile(vm.O3D, vm.X3D, vm.Y3D, outer_contour, [inner_contour], (height - 2 * thickness) * vm.Z3D,