def Geometry(self): pas = 2 * npy.pi / self.Z O = vm.Point2D((self.Ox, self.Oy)) A = O.Translation(vm.Point2D((0, self.DE / 2.))) Bp = O.Translation(vm.Point2D((0, self.DI / 2.))) B = Bp.Rotation(O, -self.alpha1, copy=True) Bi = B.Rotation(O, -self.alpha2 / 2., copy=True) C = B.Rotation(O, -self.alpha2, copy=True) D = A.Rotation(O, -self.alpha1 - self.alpha2 - self.alpha3, copy=True) Di = D.Rotation(O, (-pas + self.alpha1 + self.alpha2 + self.alpha3) / 2., copy=True) Ap = A.Rotation(O, -pas, copy=True) dir1 = (B[1] - A[1]) / (B[0] - A[0]) ord1 = B[1] - dir1 * B[0] def fonct(x, *data): Ox, Oy, R, coeff_dir, ord_origine = data f = (ord_origine + coeff_dir * x - Oy)**2 + (x - Ox)**2 - R**2 return f x1 = fsolve(fonct, 0, args=(self.Ox, self.Oy, self.DF / 2., dir1, ord1)) R1 = vm.Point2D((x1, ord1 + x1 * dir1)) dir2 = (D[1] - C[1]) / (D[0] - C[0]) ord2 = C[1] - dir2 * C[0] x2 = fsolve(fonct, 1, args=(self.Ox, self.Oy, self.DF / 2., dir2, ord2)) R2 = vm.Point2D((x2, ord2 + x2 * dir2)) li = [B, Bi, C, D, Di, Ap] AB = vm.LineSegment2D(A, B) BC = vm.Arc2D(B, Bi, C) CD = vm.LineSegment2D(C, D) list_seg = [] Am = A for z in range(self.Z): li_point = [] for pt in li: li_point.append(pt.Rotation(O, -pas * z, copy=True)) AB = vm.LineSegment2D(Am, li_point[0]) BC = vm.Arc2D(li_point[0], li_point[1], li_point[2]) CD = vm.LineSegment2D(li_point[2], li_point[3]) DA = vm.Arc2D(li_point[3], li_point[4], li_point[5]) list_seg.extend([AB, BC, CD, DA]) Am = li_point[5] c = vm.CompositePrimitive2D(list_seg) return c
def update(self, new_height, new_side): return Component(self.center, new_side, self.vectors[0], self.vectors[1], new_height, self.plane) self.points = self.compo_points() self.primitives = [ vm.LineSegment2D(self.points[0], self.points[1]), vm.LineSegment2D(self.points[1], self.points[2]), vm.LineSegment2D(self.points[2], self.points[3]), vm.LineSegment2D(self.points[3], self.points[0]) ] self.contour = vm.Contour2D(self.primitives) self.solid = self.compo_solid() return
def __init__(self, center, compo_side, vector1, vector2, height, plane): self.center = center self.compo_side = compo_side self.vectors = [vector1, vector2] self.height = height self.plane = plane self.points = self.compo_points() self.primitives = [ vm.LineSegment2D(self.points[0], self.points[1]), vm.LineSegment2D(self.points[1], self.points[2]), vm.LineSegment2D(self.points[2], self.points[3]), vm.LineSegment2D(self.points[3], self.points[0]) ] self.contour = vm.Contour2D(self.primitives) self.solid = self.compo_solid()
def Draw(self, x3D=vm.X3D, y3D=vm.Y3D, ax=None): if ax is None: fig = plt.figure() ax = fig.add_subplot(111) for point in self.active_points: vm.LineSegment2D(point, self.central_point).MPLPlot(ax)
def Geometry(self): O = vm.Point2D((self.Ox, self.Oy)) A = O.Translation(vm.Point2D((self.LA*npy.cos(self.alpha0), self.LA*npy.sin(self.alpha0)))) alpha = self.alpha0 - self.alphaA B = A.Translation(vm.Point2D((self.L1*npy.cos(alpha), self.L1*npy.sin(alpha)))) alpha = alpha - self.alphaB P = B.Translation(vm.Point2D((self.L2*npy.cos(alpha), self.L2*npy.sin(alpha)))) alpha = alpha + self.alphaP M = P.Translation(vm.Point2D((self.L5*npy.cos(alpha), self.L5*npy.sin(alpha)))) alpha = self.alpha0 - self.alphaE E = O.Translation(vm.Point2D((self.LE*npy.cos(alpha), self.LE*npy.sin(alpha)))) alphap = alpha - self.alpha1 C = E.Translation(vm.Point2D((self.L4*npy.cos(alphap), self.L4*npy.sin(alphap)))) D = E.Translation(vm.Point2D((-self.L3*npy.cos(alphap), -self.L3*npy.sin(alphap)))) alpha = alphap + npy.pi/2. - self.alphaC F = C.Translation(vm.Point2D((self.L7*npy.cos(alpha), self.L7*npy.sin(alpha)))) alpha = alphap + npy.pi/2. + self.alphaD G = D.Translation(vm.Point2D((self.L6*npy.cos(alpha), self.L6*npy.sin(alpha)))) AB=vm.LineSegment2D(A, B) BP=vm.LineSegment2D(B, P) PM=vm.LineSegment2D(P, M) DE=vm.LineSegment2D(D, E) EC=vm.LineSegment2D(E, C) DG=vm.LineSegment2D(D, G) CF=vm.LineSegment2D(C, F) alpha = alphap - npy.pi/2. R = E.Translation(vm.Point2D((self.DI/2.*npy.cos(alpha), self.DI/2.*npy.sin(alpha)))) # recherche du point F1 et F2 def fonct(alpha, *data): line, d = data x = R.Translation(vm.Point2D((d/2.*npy.cos(alpha + npy.pi/2.), d/2.*npy.sin(alpha + npy.pi/2.)))) p = line.PointProjection(x) return p.PointDistance(x) sol1 = fsolve(fonct, 0, args=(DG, self.DF)) F1 = R.Translation(vm.Point2D((self.DF/2.*npy.cos(npy.pi/2. + sol1), self.DF/2.*npy.sin(npy.pi/2. + sol1)))) sol2 = fsolve(fonct, 0, args=(CF, self.DF)) F2 = R.Translation(vm.Point2D((self.DF/2.*npy.cos(npy.pi/2. + sol2), self.DF/2.*npy.sin(npy.pi/2. + sol2)))) Cr = vm.Circle2D(R, self.DF/2.) c=vm.CompositePrimitive2D([O, AB, BP, PM, DE, EC, DG, CF, R, Cr, F1, F2]) c.MPLPlot(style='--ob')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Feb 12 19:23:27 2019 @author: steven """ import volmdlr as vm import math r = 0.23 p1 = vm.Point2D((0, 0)) p2 = vm.Point2D((r, r)) p3 = vm.Point2D((2 * r, 0)) a = vm.Arc2D(p1, p2, p3) l = vm.LineSegment2D(p3, p1) c = vm.Contour2D([a, l]) f, ax = c.MPLPlot() cog = c.CenterOfMass() cog.MPLPlot(ax) assert math.isclose(a.radius, r) assert math.isclose(c.Area(), math.pi * r**2 / 2.) assert math.isclose(cog[0], r) print(cog[1], 4 * r / 3. * math.pi) assert math.isclose(cog[1], 4 * r / 3. / math.pi)
offset_theta1 = random.randrange( angle_min, angle_max, 20) / 100 #Theta's offset if you want to turn it with normal's reference offset_phi1 = random.randrange(angle_min, angle_max, 20) / 100 #Idem but with circle's normal print('param1', phi1, theta1, offset_phi1, offset_theta1) #You have to create a cutting pattern in 2D pt1, pt2, pt3, pt4 = volmdlr.Point2D( (offset_theta1, offset_phi1)), volmdlr.Point2D( (offset_theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1)) seg1, seg2, seg3, seg4 = volmdlr.LineSegment2D( pt1, pt2), volmdlr.LineSegment2D(pt2, pt3), volmdlr.LineSegment2D( pt3, pt4), volmdlr.LineSegment2D(pt4, pt1) edges = [seg1, seg2, seg3, seg4] contours2d = [volmdlr.Contour2D(edges)] points = [theta1, phi1] #Cylinder hmin, hmax = -50, 50 h2 = random.randrange(hmin, hmax, 5) / 100 #Height of cylinder angle_cyl = random.randrange(angle_min, angle_max, 20) / 100 center2d2 = c2.To2D(c2, plane2.vectors[0], plane2.vectors[1]) segbh2 = volmdlr.LineSegment2D(center2d2, center2d2 + volmdlr.Point2D( (0, h2)) + volmdlr.Point2D( (angle_cyl / 3, 0))) #### Minus Pt2D because of Step adaptation
offset_theta1 = random.randrange( angle_min, angle_max, 20) / 100 #Theta's offset if you want to turn it with normal's reference offset_phi1 = random.randrange(angle_min, angle_max, 20) / 100 #Idem but with circle's normal print('param1', phi1, theta1, offset_phi1, offset_theta1) #You have to create a cutting pattern in 2D pt1, pt2, pt3, pt4 = volmdlr.Point2D( (offset_theta1, offset_phi1)), volmdlr.Point2D( (offset_theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1)) seg1, seg2, seg3, seg4 = volmdlr.LineSegment2D( pt1, pt2), volmdlr.LineSegment2D(pt2, pt3), volmdlr.LineSegment2D( pt3, pt4), volmdlr.LineSegment2D(pt4, pt1) edges = [seg1, seg2, seg3, seg4] contours2d = [volmdlr.Contour2D(edges)] points = [theta1, phi1] theta2 = random.randrange(angle_min, angle_max, 20) / 100 #Tore's length phi2 = random.randrange(angle_min, angle_max, 20) / 100 #angle of circle offset_theta2 = random.randrange( angle_min, angle_max, 20) / 100 #Theta's offset if you want to turn it with normal's reference offset_phi2 = random.randrange(angle_min, angle_max, 20) / 100 #Idem but with circle's normal print('param2', phi2, theta2, offset_phi2, offset_theta2)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Fri May 12 10:04:09 2017 @author: steven """ import volmdlr as vm l = 0.1 p1 = vm.Point2D((0, 0)) p2 = vm.Point2D((l, 0)) p3 = vm.Point2D((l, l)) p4 = vm.Point2D((0, l)) l1 = vm.LineSegment2D(p1, p2) l2 = vm.LineSegment2D(p2, p3) l3 = vm.LineSegment2D(p3, p4) l4 = vm.LineSegment2D(p4, p1) p5 = vm.Point2D((l / 2, l / 2)) c1 = vm.Circle2D(p5, l / 5) ct1 = vm.Contour2D([l4, l3, l2, l1]) ct2 = vm.Contour2D([c1]) mesh = vm.Mesh2D([ct1, ct2], {}, 0.01) print(mesh.GeoScript('mesh2D.geo'))
center = vm.Point3D([0, 0, 0]) #Choose the coordinate of the center normal1 = vm.Vector3D([0, 0, 1]) #Choose the normal of the generative normal1.Normalize() #Normalize the normal if it is not the case vec1 = normal1.deterministic_unit_normal_vector() frame = vm.Frame3D(center, vec1, normal1.Cross(vec1), normal1) #Frame in the center of the generative arc3D toroidalsurface3d = vm.ToroidalSurface3D(frame, r1, r2) theta = 4 * math.pi / 3 #Tore's length phi = 2 * math.pi #angle of circle offset_theta = math.pi / 4 #Theta's offset if you want to turn it with normal's reference offset_phi = math.pi #Idem but with circle's normal #You have to create a cutting pattern in 2D pt1, pt2, pt3, pt4 = vm.Point2D((offset_theta, offset_phi)), vm.Point2D( (offset_theta, offset_phi + phi)), vm.Point2D( (offset_theta + theta, offset_phi + phi)), vm.Point2D( (offset_theta + theta, offset_phi)) seg1, seg2, seg3, seg4 = vm.LineSegment2D(pt1, pt2), vm.LineSegment2D( pt2, pt3), vm.LineSegment2D(pt3, pt4), vm.LineSegment2D(pt4, pt1) edges = [seg1, seg2, seg3, seg4] contours2d = [vm.Contour2D(edges)] points = [theta, phi] toroidalface = vm.ToroidalFace3D(contours2d, toroidalsurface3d, points) shell = vm.Shell3D([toroidalface]) m = vm.VolumeModel([shell]) m.babylonjs(debug=True)
def Draw(self, ax=None): if ax is None: fig = plt.figure() ax = fig.add_subplot(111) vm.LineSegment2D(*self.points).MPLPlot(ax)
offset_theta1 = random.randrange( angle_min, angle_max, 20) / 100 #Theta's offset if you want to turn it with normal's reference offset_phi1 = random.randrange(angle_min, angle_max, 20) / 100 #Idem but with circle's normal print('param1', phi1, theta1, offset_phi1, offset_theta1) #You have to create a cutting pattern in 2D pt1, pt2, pt3, pt4 = volmdlr.Point2D( (offset_theta1, offset_phi1)), volmdlr.Point2D( (offset_theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1 + phi1)), volmdlr.Point2D( (offset_theta1 + theta1, offset_phi1)) seg1, seg2, seg3, seg4 = volmdlr.LineSegment2D( pt1, pt2), volmdlr.LineSegment2D(pt2, pt3), volmdlr.LineSegment2D( pt3, pt4), volmdlr.LineSegment2D(pt4, pt1) edges = [seg1, seg2, seg3, seg4] contours2d = [volmdlr.Contour2D(edges)] points = [theta1, phi1] toroidalface1 = volmdlr.ToroidalFace3D(contours2d, toresurface1, points) pts1, tangle1 = toroidalface1.triangulation(resolution=10) # number_holes = 5 # outer_circle = volmdlr.Circle2D(volmdlr.O2D, 0.06) # circles = [] # delta_angle = 2*math.pi/number_holes
Distance to lines and projection debug """ import numpy as npy import volmdlr as vm p1 = vm.Point2D(2*npy.random.random(2)-1) p2 = vm.Point2D(2*npy.random.random(2)-1) line = vm.Line2D(p1, p2) line_segment = vm.LineSegment2D(p1, p2) for i in range(100): point = vm.Point2D(4*npy.random.random(2)-2) point_projection_line = line.PointProjection(point) point_projection_line_segment = line_segment.PointProjection(point) assert point_projection_line.PointDistance(point) == line.PointDistance(point) assert point_projection_line_segment.PointDistance(point) == line_segment.PointDistance(point) #fig, ax = line.MPLPlot() #point.MPLPlot(ax=ax) #point_projection_line.MPLPlot(ax=ax) #point_projection_line_segment.MPLPlot(ax=ax)
def rolling_circle_in_polygon(polygon, interpoints_distance=0.001): # discrétisation du polygon polygon_mesh = [] # on partcourt les arrêtes for (vertice1, vertice2) in zip(polygon.points, polygon.points[1:]+[polygon.points[0]]): side_direction = vm.Vector2D((vertice2[0] - vertice1[0], vertice2[1] - vertice1[1])) normalized_side_direction = vm.Vector2D((vertice2[0] - vertice1[0], vertice2[1] - vertice1[1])) normalized_side_direction.Normalize() pt_number = 0 # on ajoute les points un par un sans dépasser la longueur du côté segment_mesh = [] while interpoints_distance * pt_number < side_direction.Norm(): side_point = vertice1 + interpoints_distance * pt_number * normalized_side_direction segment_mesh.append(side_point) pt_number += 1 polygon_mesh.append(segment_mesh) # prendre un point quelconque # construire le plus grand cercle possible min_radius = 1e+10 for index1, segment1 in enumerate(polygon_mesh): for index2, segment2 in enumerate(polygon_mesh): if index2-index1 >= 2 and index2-index1 < len(polygon_mesh)-1: for point1 in segment1[1:]: seg1 = vm.LineSegment2D(segment1[0], segment1[-1]) seg2 = vm.LineSegment2D(segment2[0], segment2[-1]) circle1, circle2 = seg2.CreateTangentCircle(point1, seg1) polygon_mesh_modified = polygon_mesh[:] polygon_mesh_modified.pop(index1) polygon_mesh_modified = [p for seg in polygon_mesh_modified for p in seg] if circle1 is not None and not points_inside_circle(polygon_mesh_modified, circle1) and circle1.radius < min_radius:# and circle1.radius != 0: min_radius = circle1.radius min_circle = circle1 other_circle = circle2 min_point = point1 min_seg1 = index1 min_seg2 = index2 for point2 in segment2[1:]: seg1 = vm.LineSegment2D(segment1[0], segment1[-1]) seg2 = vm.LineSegment2D(segment2[0], segment2[-1]) circle1, circle2 = seg1.CreateTangentCircle(point2, seg2) polygon_mesh_modified = polygon_mesh[:] polygon_mesh_modified.pop(index2) polygon_mesh_modified = [p for seg in polygon_mesh_modified for p in seg] if circle1 is not None and not points_inside_circle(polygon_mesh_modified, circle1) and circle1.radius < min_radius:# and circle1.radius != 0: min_radius = circle1.radius min_circle = circle1 other_circle = circle2 min_point = point2 min_seg1 = index2 min_seg2 = index1 return min_radius, min_circle, other_circle, min_point, min_seg1, min_seg2
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.RoundedLineSegments2D([p1, p2, p3, p4, p5], radius, closed=True) #hole = vm.Circle2D(p6, 0.01) #inner_profile = primitives2D.RoundedLineSegments2D([p6, p7, p8], {0: }, closed = True) l1 = vm.LineSegment2D(p6, p7) l2 = vm.LineSegment2D(p7, p8) l3 = vm.LineSegment2D(p8, p6) c2 = vm.Contour2D([l1, l2, l3]) c1 = vm.Contour2D([outer_profile]) #c2 = vm.Contour2D([inner_profile]) po = vm.Point3D((0, 0, 0)) xp = vm.Vector3D((1, 0, 0)) yp = vm.Vector3D((0, 1, 0)) f, a = c1.MPLPlot() c2.MPLPlot(a) profile = primitives3D.ExtrudedProfile(po, xp,
n1.Normalize() #Normalize the normal if it is not the case n2.Normalize() plane1, plane2 = volmdlr.Plane3D.from_normal(c1, n1), volmdlr.Plane3D.from_normal(c2, n2) #Create a plane to give us two others vector frame1 = volmdlr.Frame3D(c1, plane1.vectors[0], plane1.vectors[1], n1) #Frame in the center of the cylinder frame2 = volmdlr.Frame3D(c2, plane2.vectors[0], plane2.vectors[1], n2) cylsurface1 = volmdlr.CylindricalSurface3D(frame1, r1) cylsurface2 = volmdlr.CylindricalSurface3D(frame2, r2) hmin, hmax = 0, 100 h1, h2 = random.randrange(hmin, hmax, 5)/100, random.randrange(hmin, hmax, 5)/100 #Height of cylinder # center2d = c1.To2D(c1, plane1.vectors[0], plane1.vectors[1]) center2d = volmdlr.Point2D((0,0)) segbh = volmdlr.LineSegment2D(center2d, center2d + volmdlr.Point2D((0,h1))) #### Minus Pt2D because of Step adaptation circlestart = volmdlr.LineSegment2D(segbh.points[1], segbh.points[1]+volmdlr.Point2D((2*math.pi*3/4,0))) #You can change 2*pi by an other angle seghb = volmdlr.LineSegment2D(circlestart.points[1],circlestart.points[1]-segbh.points[1]) circlend = volmdlr.LineSegment2D(seghb.points[1],segbh.points[0]) edges = [segbh, circlestart, seghb, circlend] points = edges[0].points contours = [volmdlr.Contour2D(edges)] # center2d2 = c2.To2D(c2, plane2.vectors[0], plane2.vectors[1]) center2d2 = volmdlr.Point2D((0,0)) segbh2 = volmdlr.LineSegment2D(center2d2, center2d2 + volmdlr.Point2D((0,h2))) #### Minus Pt2D because of Step adaptation circlestart2 = volmdlr.LineSegment2D(segbh2.points[1], segbh2.points[1]+volmdlr.Point2D((2*math.pi,0))) #You can change 2*pi by an other angle seghb2 = volmdlr.LineSegment2D(circlestart2.points[1],circlestart2.points[1]-segbh2.points[1]) circlend2 = volmdlr.LineSegment2D(seghb2.points[1],segbh2.points[0]) edges2 = [segbh2, circlestart2, seghb2, circlend2] points2 = edges2[0].points
Created on Wed Mar 14 15:32:37 2018 @author: Steven Masfaraud [email protected] """ import volmdlr as vm import volmdlr.primitives2D as primitives2D import numpy as npy #for i in range(20): triangle_points = [vm.Point2D(npy.random.random(2)) for i in range(3)] triangle = vm.Polygon2D(triangle_points) cog_triangle = triangle.CenterOfMass() c1 = vm.CompositePrimitive2D([triangle, cog_triangle]) c1.MPLPlot() print(triangle.Area()) p0 = vm.Point2D((-1, 0)) p1 = vm.Point2D((-npy.cos(npy.pi / 4), npy.sin(npy.pi / 4))) p2 = vm.Point2D((0, 1)) a = vm.Arc2D(p2, p1, p0) l = vm.LineSegment2D(p2, a.center) list_node = a.Discretise() c = vm.Contour2D([a, l] + list_node) print(c.plot_data()) c2 = vm.CompositePrimitive2D([c]) c2.MPLPlot(style='ob') print(c.Area())
n1 = volmdlr.Vector3D([x3, y3, z3]) n1.Normalize() #Normalize the normal if it is not the case plane1 = volmdlr.Plane3D.from_normal(c1, n1) frame1 = volmdlr.Frame3D(c1, plane1.vectors[0], plane1.vectors[1], n1) #Frame in the center of the cylinder cylsurface1 = volmdlr.CylindricalSurface3D(frame1, r1) hmin, hmax = -50, 50 h1 = random.randrange(hmin, hmax, 5) / 100 center2d = c1.To2D(c1, plane1.vectors[0], plane1.vectors[1]) #Classic Contour segbh = volmdlr.LineSegment2D(center2d, center2d + volmdlr.Point2D( (0, h1))) #### Minus Pt2D because of Step adaptation circlestart = volmdlr.LineSegment2D( segbh.points[1], segbh.points[1] + volmdlr.Point2D( (2 * math.pi * 3 / 4, 0))) #You can change 2*pi by an other angle seghb = volmdlr.LineSegment2D(circlestart.points[1], circlestart.points[1] - segbh.points[1]) circlend = volmdlr.LineSegment2D(seghb.points[1], segbh.points[0]) edges = [segbh, circlestart, seghb, circlend] points = edges[0].points contours = [volmdlr.Contour2D(edges)] cyl1 = volmdlr.CylindricalFace3D(contours, cylsurface1, points) pts1, tangle1 = cyl1.triangulation(resolution=12) fig = plt.figure()