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')
@author: Mack Pro """ import numpy as npy import volmdlr as volmdlr import volmdlr.primitives3D as primitives3D import volmdlr.primitives2D as primitives2D import matplotlib.pyplot as plt import random ######## SWEEP TEST RANDOM nb_point1, nb_point2 = 6, 5 radius_circle1, radius_circle2 = 0.008, 0.01 c1 = volmdlr.Circle2D(volmdlr.Point2D((0, 0)), radius_circle1) contour1 = volmdlr.Contour2D([c1]) c2 = volmdlr.Circle2D(volmdlr.Point2D((0, 0)), radius_circle2) contour2 = volmdlr.Contour2D([c2]) mini, maxi = -1, 1 pts1 = [] for k in range(nb_point1): a1, a2, a3 = random.randint(mini, maxi), random.randint( mini, maxi), random.randint(mini, maxi) c1, c2, c3 = random.randrange(0, 100, 1), random.randrange( 0, 100, 1), random.randrange(0, 100, 1) pts1.append(volmdlr.Point3D((a1 * c1 / 100, a2 * c2 / 100, a3 * c3 / 100))) radius1 = {
# -*- coding: utf-8 -*- """ Created on Tue May 12 17:14:06 2020 @author: masfaraud """ import numpy as npy import volmdlr as volmdlr import volmdlr.primitives3D as primitives3D import volmdlr.primitives2D as primitives2D import matplotlib.pyplot as plt import random radius_circle = 0.008 c = volmdlr.Circle2D(volmdlr.Point2D((0, 0)), radius_circle) contour = volmdlr.Contour2D([c]) pt0 = volmdlr.Point3D((0.01, 0.04, 0.16)) pt1 = volmdlr.Point3D((0.03, 0, 0.2)) pt2 = volmdlr.Point3D((0.45, 0.01, 0.1)) pt3 = volmdlr.Point3D((0.45, 0, -0.1)) pt4 = volmdlr.Point3D((0.3, 0.04, -0.02)) pts = [pt0, pt1, pt2, pt3, pt4] radius = {1: 0.03, 2: 0.01, 3: 0.07} rl = primitives3D.OpenedRoundedLineSegments3D(pts, radius, adapt_radius=True, name='wire') sweep = primitives3D.Sweep(contour, rl, name='pipe') pt10 = volmdlr.Point3D((0.02, 0.22, 0.25))
p4 = vm.Point2D((0, r1)) p4.Rotation(pc, theta1 + theta3, False) p5 = p4.Rotation(pc, theta2) p6 = p1.Rotation(pc, theta) l1 = primitives2D.RoundedLineSegments2D([p3, p4, p5, p6], {1: r3, 2: r3}) #l1=primitives2D.RoundedLines2D([p1,p2,p3,p4],{0:0.01,2:0.01}) #l2=vm.Circle2D(p5,0.01) L = [a1, l1] for i in range(Z - 1): thetar = (i + 1) * theta L.append(a1.Rotation(pc, thetar, True)) L.append(l1.Rotation(pc, thetar, True)) #p7=vm.Point2D((0,r4)) l2 = vm.Circle2D(pc, r4) c1 = vm.Contour2D(L) c2 = vm.Contour2D([l2]) po = vm.Point3D((0, 0, 0)) xp = vm.Vector3D((1, 0, 0)) yp = vm.Vector3D((0, 1, 0)) #c1.MPLPlot() #extr_vect=vm.Vector3D((0,0,e)) profile_straight = primitives3D.ExtrudedProfile(po, xp, yp, c1, [c2], (0, 0, e),
def transversal_plot(self, offset=0, ax=None): oc = vm.Circle2D(vm.O2D, self.overall_rim_diameter * 0.5) fig, ax = oc.plot(ax=ax) for circle in self.bolt_circles(): circle.plot(ax=ax) return fig, ax
#!/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'))
def circle_1_point_2_segments(point, line1, line2): # point will be called I(x_I, y_I) # semgent1 will be [AB] # segment2 will be [CD] I = vm.Vector2D((point[0], point[1])) A = vm.Vector2D((line1.points[0][0], line1.points[0][1])) B = vm.Vector2D((line1.points[1][0], line1.points[1][1])) C = vm.Vector2D((line2.points[0][0], line2.points[0][1])) D = vm.Vector2D((line2.points[1][0], line2.points[1][1])) # CHANGEMENT DE REPAIRE new_u = vm.Vector2D((B-A)) new_u.Normalize() new_v = new_u.NormalVector(unit=True) new_basis = vm.Frame2D(I, new_u, new_v) new_A = new_basis.NewCoordinates(A) new_B = new_basis.NewCoordinates(B) new_C = new_basis.NewCoordinates(C) new_D = new_basis.NewCoordinates(D) # ============================================================================= # LES SEGMENTS DECRIVENT UNE SEULE ET MEME DROITE # => AUCUNE SOLUTION # ============================================================================= if new_C[1] == 0 and new_D[1] == 0: return None, None # ============================================================================= # LES SEGMENTS SONT PARALLELES # => 1 SOLUTION # ============================================================================= elif math.isclose(line1.DirectionVector(unit=True).Dot(line2.NormalVector(unit=True)), 0, abs_tol=1e-06): segments_distance = abs(new_C[1] - new_A[1]) r = segments_distance / 2 new_circle_center = vm.Point2D((0, r)) circle_center = new_basis.OldCoordinates(new_circle_center) circle = vm.Circle2D(circle_center, r) return circle, None # ============================================================================= # LES SEGMENTS SONT PERPENDICULAIRES # => 2 SOLUTIONS # ============================================================================= elif math.isclose(line1.DirectionVector(unit=True).Dot(line2.DirectionVector(unit=True)), 0, abs_tol=1e-06): line_AB = vm.Line2D(vm.Point2D(new_A), vm.Point2D(new_B)) line_CD = vm.Line2D(vm.Point2D(new_C), vm.Point2D(new_D)) new_pt_K = vm.Point2D.LinesIntersection(line_AB ,line_CD) r = abs(new_pt_K[0]) new_circle_center1 = vm.Point2D((0, r)) new_circle_center2 = vm.Point2D((0, -r)) circle_center1 = new_basis.OldCoordinates(new_circle_center1) circle_center2 = new_basis.OldCoordinates(new_circle_center2) circle1 = vm.Circle2D(circle_center1, r) circle2 = vm.Circle2D(circle_center2, r) return circle1, circle2 # ============================================================================= # LES SEGMENTS SONT QUELCONQUES # => 2 SOLUTIONS # ============================================================================= else: line_AB = vm.Line2D(vm.Point2D(new_A), vm.Point2D(new_B)) line_CD = vm.Line2D(vm.Point2D(new_C), vm.Point2D(new_D)) new_pt_K = vm.Point2D.LinesIntersection(line_AB ,line_CD) pt_K = vm.Point2D(new_basis.OldCoordinates(new_pt_K)) # CHANGEMENT DE REPERE: new_u2 = vm.Vector2D(pt_K-I) new_u2.Normalize() new_v2 = new_u2.NormalVector(unit=True) new_basis2 = vm.Frame2D(I, new_u2, new_v2) new_A = new_basis2.NewCoordinates(A) new_B = new_basis2.NewCoordinates(B) new_C = new_basis2.NewCoordinates(C) new_D = new_basis2.NewCoordinates(D) new_pt_K = new_basis2.NewCoordinates(pt_K) teta1 = math.atan2(new_C[1], new_C[0] - new_pt_K[0]) teta2 = math.atan2(new_D[1], new_D[0] - new_pt_K[0]) if teta1 < 0: teta1 += math.pi if teta2 < 0: teta2 += math.pi if not math.isclose(teta1, teta2, abs_tol=1e-08): if math.isclose(teta1, math.pi, abs_tol=1e-08) or math.isclose(teta1, 0., abs_tol=1e-08): teta = teta2 elif math.isclose(teta2, math.pi, abs_tol=1e-08) or math.isclose(teta2, 0., abs_tol=1e-08): teta = teta1 else: teta = teta1 r1 = new_pt_K[0] * math.sin(teta) / (1 + math.cos(teta)) r2 = new_pt_K[0] * math.sin(teta) / (1 - math.cos(teta)) new_circle_center1 = vm.Point2D((0, -r1)) new_circle_center2 = vm.Point2D((0, r2)) circle_center1 = new_basis2.OldCoordinates(new_circle_center1) circle_center2 = new_basis2.OldCoordinates(new_circle_center2) if new_basis.NewCoordinates(circle_center1)[1] > 0: circle1 = vm.Circle2D(circle_center1, r1) circle2 = vm.Circle2D(circle_center2, r2) else: circle1 = vm.Circle2D(circle_center2, r2) circle2 = vm.Circle2D(circle_center1, r1) return circle1, circle2
Created on Tue May 26 09:45:01 2020 @author: Mack Pro """ import volmdlr as volmdlr import volmdlr.primitives3D as primitives3D import volmdlr.primitives2D as primitives2D import random import math posmin, posmax = -100, 100 number_holes = 5 outer_circle = volmdlr.Circle2D(volmdlr.O2D, 0.06) circles = [] delta_angle = 2*math.pi/number_holes inner_circle = volmdlr.Circle2D(volmdlr.O2D, 0.04) first_circle = volmdlr.Circle2D(volmdlr.Point2D((0, 0.05)), 0.005) circles = [inner_circle, first_circle] for i in range(1, number_holes): circles.append(first_circle.Rotation(volmdlr.O2D, i*delta_angle)) xn, yn, zn = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 xc, yc, zc = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 n = volmdlr.Vector3D([xn,yn,zn]) n.Normalize() c = volmdlr.Point3D((xc,yc,zc))
f, a = inner_contour.MPLPlot() outer_contour.MPLPlot(a) sides = primitives3D.ExtrudedProfile(vm.o3D, vm.x3D, vm.y3D, outer_contour, [inner_contour], (height - 2 * thickness) * vm.z3D, 'sides') bottom = primitives3D.ExtrudedProfile(vm.o3D, vm.x3D, vm.y3D, outer_contour, [], -thickness * vm.z3D, 'bottom') screw_holes_rl = inner_rl.Offset(-(thickness + screw_holes_clearance + 0.5 * screw_holes_diameter)) screw_holes = [] l = screw_holes_rl.Length() for i in range(n_screws): s = i * l / n_screws p = screw_holes_rl.PointAtCurvilinearAbscissa(s) screw_holes.append( vm.Contour2D([vm.Circle2D(p, screw_holes_diameter * 0.5)])) belt_outer_rl = inner_rl.Offset(-(2 * screw_holes_clearance + screw_holes_diameter + thickness)) belt_outer_contour = vm.Contour2D([belt_outer_rl]) belt = primitives3D.ExtrudedProfile(vm.z3D * (height - 2 * thickness), vm.x3D, vm.y3D, belt_outer_contour, [inner_contour] + screw_holes, thickness * vm.z3D, 'belt') casing = vm.primitives3D.Fuse([bottom, sides, belt], 'Lower Casing') model = vm.VolumeModel([('casing', [casing])]) model.FreeCADExport('casing')
p15 = vm.Point2D((0.03, 0.05)) points1 = [ p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15 ] c1 = primitives2D.ClosedRoundedLineSegments2D(points1, { 2: 0.005, 3: 0.005, 4: 0.005, 8: 0.005, 9: 0.005, 10: 0.005, 14: 0.005 }) circle0 = vm.Circle2D(vm.Point2D((0.12, 0.25)), 0.02) circle1 = vm.Circle2D(vm.Point2D((0.19, 0.25)), 0.02) circle2 = vm.Circle2D(vm.Point2D((0.15, 0.08)), 0.08) c2 = vm.Contour2D([circle0]) c3 = vm.Contour2D([circle1]) c4 = vm.Contour2D([circle2]) e0 = vm.Point2D((0, 0.00)) e1 = vm.Point2D((0, 0.03)) e2 = vm.Point2D((0.11, 0.03)) e3 = vm.Point2D((0.11, 0.04)) e4 = vm.Point2D((0.13, 0.04)) e5 = vm.Point2D((0.13, 0)) points2 = [e0, e1, e2, e3, e4, e5] c5 = primitives2D.ClosedRoundedLineSegments2D(points2, {})
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Mar 14 13:55:59 2017 @author: steven """ # Debug of area and inertia import volmdlr as vm r = 0.05 p1 = vm.Point2D((0, 0)) p2 = vm.Point2D((0, -r)) p3 = vm.Point2D((r, 0)) p4 = vm.Point2D((0, r)) c1 = vm.Arc2D(p2, p3, p4) print(c1.SecondMomentArea(p1)) c2 = vm.Circle2D(p1, r) print(c2.SecondMomentArea(p1))
x, y, outer_contour, [], -thickness_min * extrusion_vector, alpha=alpha, name='bottom') # Screw screw_holes_rl = inner_contour.Offset(-(thickness + screw_holes_clearance + 0.5 * screw_holes_diameter)) screw_holes = [] l = screw_holes_rl.Length() for i in range(n_screws): s = i * l / n_screws p = screw_holes_rl.PointAtCurvilinearAbscissa(s) screw_holes.append(vm.Circle2D(p, screw_holes_diameter * 0.5)) # Belt belt_outer_contour = inner_contour.Offset( -(2 * screw_holes_clearance + screw_holes_diameter + thickness)) belt = primitives3D.ExtrudedProfile( origin + basis_plane.normal * height_bot_belt, x, y, belt_outer_contour, [inner_contour] + screw_holes, height_belt * extrusion_vector, alpha=alpha, name='belt') # Hat floors
def transversal_plot(self, ax=None): oc = vm.Circle2D(vm.O2D, self.diameter * 0.5) ic = vm.Circle2D(vm.O2D, self.rim_diameter * 0.5) fig, ax = oc.MPLPlot(ax=ax) ic.MPLPlot(ax=ax) return fig, ax