def volmdlr_primitives(self): primitives = [] pos = vm.Point3D(self.pos_x, self.pos_y, self.z_position) axis = vm.Vector3D(0, 0, 1) cylinder = p3d.Cylinder(pos, axis, self.diameter / 2, self.length) primitives.append(cylinder) return primitives
def babylon(self, length, z_position): primitives = [] pos = vm.Point3D((self.pos_x, self.pos_y, z_position)) axis = vm.Vector3D((0, 0, 1)) radius = 0.02 cylinder = p3d.Cylinder(pos, axis, radius, length) primitives.append(cylinder) return primitives
def babylon(self, xy_position, z_position): primitives = [] pos = vm.Point3D((xy_position[0], xy_position[1], z_position)) axis = vm.Vector3D((0, 0, 1)) radius = self.diameter / 2 length = self.length cylinder = p3d.Cylinder(pos, axis, radius, length) primitives.append(cylinder) return primitives
def Babylon(self): new_axis = volmdlr.Vector3D((self.axis[0], self.axis[1], self.axis[2])) normal_vector1 = new_axis.RandomUnitNormalVector() normal_vector2 = new_axis.Cross(normal_vector1) x, y, z = self.position s = 'var cylinder = BABYLON.Mesh.CreateCylinder("{}", {}, {}, {}, 30, 1, scene,false, BABYLON.Mesh.DEFAULTSIDE);'.format( self.name, self.length, 2 * self.radius, 2 * self.radius) s += 'cylinder.position = new BABYLON.Vector3({},{},{});\n;'.format( x, y, z) s += 'var axis1 = new BABYLON.Vector3({},{},{});\n'.format( new_axis[0], new_axis[1], new_axis[2]) s += 'var axis2 = new BABYLON.Vector3({},{},{});\n'.format( normal_vector1[0], normal_vector1[1], normal_vector1[2]) s += 'var axis3 = new BABYLON.Vector3({},{},{});\n'.format( normal_vector2[0], normal_vector2[1], normal_vector2[2]) s += 'cylinder.rotation = BABYLON.Vector3.RotationFromAxis(axis3, axis1, axis2);\n' return s
def babylon(self, xy_position, z_position): primitives = [] ## AFFICHAGE EN CYLINDRE ## # pos = vm.Point3D((xy_position[0], xy_position[1], z_position)) # axis = vm.Vector3D((0,0,1)) # radius = self.diameter/2 # length = self.length # cylinder = p3d.Cylinder(pos, axis, radius, length) # primitives.append(cylinder) ## AFFICHAGE EN ROUE DENTEE ## plane_origin = vm.Point3D( (xy_position[0], xy_position[1], z_position - self.length / 2)) x = vm.x3D y = vm.y3D vector = vm.Vector3D((0, 0, self.length)) if self.n_teeth is None: n_teeth = int(round(self.diameter * 100, 0)) else: n_teeth = self.n_teeth angle = 2 * math.pi / n_teeth inner_diameter = 0.90 * self.diameter teeth_l = (2 * math.pi * self.diameter / 2) / (1.5 * n_teeth) pt1 = vm.Point2D( (-teeth_l / 2, (inner_diameter**2 / 4 - teeth_l**2 / 4)**0.5)) pt5 = vm.Point2D( (teeth_l / 2, (inner_diameter**2 / 4 - teeth_l**2 / 4)**0.5)) pt2 = vm.Point2D((pt1.vector[0] / 2, self.diameter / 2)) pt4 = vm.Point2D((pt5.vector[0] / 2, self.diameter / 2)) rls_points = [pt1, pt2, pt4, pt5] for i in range(n_teeth - 1): new_pt1 = rls_points[-4].Rotation(vm.o2D, -angle) new_pt2 = rls_points[-3].Rotation(vm.o2D, -angle) new_pt4 = rls_points[-2].Rotation(vm.o2D, -angle) new_pt5 = rls_points[-1].Rotation(vm.o2D, -angle) rls_points.extend([new_pt1, new_pt2, new_pt4, new_pt5]) rls_points.reverse() rls = p2d.OpenedRoundedLineSegments2D(rls_points, {}) outer_contour2d = vm.Contour2D([rls]) extrusion = p3d.ExtrudedProfile(plane_origin, x, y, outer_contour2d, [], vector) primitives.append(extrusion) return primitives
def Babylon(self): new_axis = volmdlr.Vector3D((self.axis[0], self.axis[1], self.axis[2])) normal_vector1 = new_axis.RandomUnitNormalVector() normal_vector2 = new_axis.Cross(normal_vector1) x, y, z = self.position s = 'var cone = BABYLON.MeshBuilder.CreateCylinder("cone", {{diameterTop:0, diameterBottom:{}, height: {}, tessellation: 100}}, scene);\n'.format( 2 * self.radius, self.length) s += 'cone.position = new BABYLON.Vector3({},{},{});\n;'.format( x, y, z) s += 'var axis1 = new BABYLON.Vector3({},{},{});\n'.format( new_axis[0], new_axis[1], new_axis[2]) s += 'var axis2 = new BABYLON.Vector3({},{},{});\n'.format( normal_vector1[0], normal_vector1[1], normal_vector1[2]) s += 'var axis3 = new BABYLON.Vector3({},{},{});\n'.format( normal_vector2[0], normal_vector2[1], normal_vector2[2]) s += 'cone.rotation = BABYLON.Vector3.RotationFromAxis(axis3, axis1, axis2);\n' return s
# -*- coding: utf-8 -*- """ Created on Thu Apr 2 15:25:47 2020 @author: Mack Pro """ import volmdlr as vm import math # import matplotlib.pyplot as plt r1 = 10e-3 #Radius of the generative arc3D r2 = 3e-3 #Radius of the arc3d generated 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(
import volmdlr as vm import volmdlr.primitives3d as primitives3d resolution = 0.0010 box = primitives3d.Block(vm.Frame3D(vm.Point3D(0.1, 0.1, 0.1), vm.Vector3D(0.15, 0.0, 0.0), vm.Vector3D(0.0, 0.15, 0.0), vm.Vector3D(0.0, 0.0, 0.15)), alpha=0.6) box.frame_mapping(vm.Frame3D(vm.Point3D(-0.07, -0.07, -0.07), vm.Point3D(1, 0, 0), vm.Point3D(0, 1, 0), vm.Point3D(0, 0, 1)), copy=False, side='old') box_red = primitives3d.Block(vm.Frame3D(vm.Point3D(-0.04, -0.04, -0.04), vm.Vector3D(0.1, 0.0, 0.0), vm.Vector3D(0.0, 0.1, 0.0), vm.Vector3D(0.0, 0.0, 0.1)), color=(0.2, 1, 0.4), alpha=0.6) assert type(box_red.shell_intersection(box, resolution=0.001)) == tuple vol = vm.core.VolumeModel([box, box_red]) vol.babylonjs()
import matplotlib.pyplot as plt import random import math rmin, rmax = 10, 100 posmin, posmax = -100, 100 x1, y1, z1 = random.randrange(posmin, posmax, 1) / 100, random.randrange( posmin, posmax, 1) / 100, random.randrange(posmin, posmax, 1) / 100 r1 = random.randrange(rmin, rmax, 1) / 1000 c1 = volmdlr.Point3D([x1, y1, z1]) x3, y3, z3 = random.randrange(posmin, posmax, 1) / 100, random.randrange( posmin, posmax, 1) / 100, random.randrange(posmin, posmax, 1) / 100 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
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Feb 28 15:33:01 2017 @author: steven """ import numpy as npy import volmdlr as vm import volmdlr.primitives3D as primitives3D cylinder1 = primitives3D.Cylinder(vm.Vector3D((0., 0., 0.)), vm.Vector3D((1., 0., 0.)), 0.03, 0.02, 'cylinder1') cylinder2 = primitives3D.HollowCylinder(vm.Vector3D((0, 0.1, 0.)), vm.Vector3D((1., 0., 0.)), 0.02, 0.06, 0.03, 'cylinder2') #profile=primitives3D.ExtrudedProfile((0,0,0),(1,0,0),(0,1,0),[(0,0),(0.1,0.),(0.15,0.4),(0.,0.3)],{0:0.05,2:0.01},(0,0,0.2)) model = vm.VolumeModel([('Cylinder 1', [cylinder1]), ('Cylinder 2', [cylinder2])]) #profile.MPLPlot((0,0,0),(1,0,0),(0,1,0)) model.FreeCADExport('cylinders') #print(model.BabylonScript()) #model.BabylonShow()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Drawing 3D primitives in 2D """ import volmdlr as vm import volmdlr.primitives3D as primitives3D b = primitives3D.Block( vm.Frame3D(vm.Point3D((1, 2.3, 4)), vm.Vector3D((0.5, 0.3, -0.1)), vm.y3D, vm.z3D)) b.MPLPlot(vm.y3D, vm.z3D)
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() #%% p1 = vm.Point2D((0, 0)) p2 = vm.Point2D((2, 0)) p3 = vm.Point2D((2, 2)) p4 = vm.Point2D((0, 2)) p5 = vm.Point2D((0.5, 0.5)) p6 = vm.Point2D((1.5, 0.5)) p7 = vm.Point2D((1.5, 1.5))
# -*- coding: utf-8 -*- """ Created on Thu Apr 2 14:09:52 2020 @author: Mack Pro """ import volmdlr as vm import math Gradius = 8e-3 #Grand radius Sradius = 3e-3 #Small radius h = 20e-3 #Height of the Ellipse center = vm.Point3D([0, 0, 0]) #Choose the coordinate of the center normal = vm.Vector3D([1, 1, 1]) #Choose the normal normal.Normalize() #Normalize the normal if it is not the case plane = vm.Plane3D.from_normal( center, normal) #Create a plane to give us two others vector Gdir = plane.vectors[0] #Gradius direction Sdir = plane.vectors[1] #Sradius direction ellipse = vm.Ellipse3D(Gradius, Sradius, center, normal, Gdir) bsplinextru = vm.BSplineExtrusion( ellipse, -normal) #Perhaps the normal needs to be the opposite angle = 5 * math.pi / 4 #Angle of pint if start=end # position of point in ellipse with an angle # Gradius*vm.Point3D(Gdir.vector)*math.cos(angle)+Sradius*vm.Point3D(Sdir.vector)*math.sin(angle)+center
posmin, posmax = -100, 100 x1, y1, z1 = random.randrange(posmin, posmax, 1) / 100, random.randrange( posmin, posmax, 1) / 100, random.randrange(posmin, posmax, 1) / 100 x2, y2, z2 = random.randrange(posmin, posmax, 1) / 100, random.randrange( posmin, posmax, 1) / 100, random.randrange(posmin, posmax, 1) / 100 R1 = random.randrange(rmin, rmax, 1) / 1000 #Radius of the generative arc3D r1 = random.randrange(rmin / 10, rmax / 10, 1) / 1000 #Radius of the arc3d generated c1 = volmdlr.Point3D([x1, y1, z1]) #Choose the coordinate of the center x3, y3, z3 = random.randrange(posmin, posmax, 1) / 100, random.randrange( posmin, posmax, 1) / 100, random.randrange(posmin, posmax, 1) / 100 n1 = volmdlr.Vector3D([x3, y3, z3]) #Choose the normal n1.Normalize() #Normalize the normal if it is not the case plane1 = volmdlr.Plane3D.from_normal( c1, n1) #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 Tore toresurface1 = volmdlr.ToroidalSurface3D(frame1, R1, r1) angle_min, angle_max = 0, 2 * 3.14 * 100 theta1 = random.randrange(angle_min, angle_max, 20) / 100 #Tore's length phi1 = 2 * math.pi #angle of circle offset_theta1 = random.randrange( angle_min, angle_max, 20) / 100 #Theta's offset if you want to turn it with normal's reference
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Oct 30 16:55:25 2019 @author: ringhausen """ import volmdlr as vm import volmdlr.primitives3d as p3d ### BLOCK DE DEPART ### origin = vm.Point3D(0, 0, 0) u = vm.Vector3D(0.2, 0, 0) v = vm.Vector3D(0, 0.2, 0) w = vm.Vector3D(0, 0, 0.2) frame = vm.Frame3D(origin, u, v, w) block_depart = p3d.Block(frame, name='test', color=(0, 0.5, 0)) ### BLOCK D'ARIVEE ### origin = vm.Point3D(1, 1, 1) u = vm.Vector3D(0.2, 0, 0) v = vm.Vector3D(0, 0.2, 0) w = vm.Vector3D(0, 0, 0.2) frame = vm.Frame3D(origin, u, v, w) block_arrivee = p3d.Block(frame, name='test', color=(0, 0, 0.5)) ### BLOCKS OBSTACLES ### origin = vm.Point3D(0.51, 0.51, 0.53) u = vm.Vector3D(0.2, 0, 0) v = vm.Vector3D(0, 0.2, 0)
""" import volmdlr as vm import volmdlr.primitives3d as p3d #bbox = vm.BoundingBox(-1, 1, -1, 1, -1, 1) ##point1 = vm.Point3D((-0.8, 1, -0.8)) ##point2 = vm.Point3D((1, 0.5, 0.5)) #point1 = vm.Point3D((-1, 0.8, 0.8)) #point2 = vm.Point3D((1, -0.7, -0.7)) # #d = bbox.distance_between_two_points_on_bbox(point1, point2) #print(d) origin = vm.Point3D((-0.5, 0.5, 0)) u = vm.Vector3D((0.7, 0, 0)) v = vm.Vector3D((0, 0.7, 0)) w = vm.Vector3D((0, 0, 0.7)) frame = vm.Frame3D(origin, u, v, w) block_obstacle1 = p3d.Block(frame, 'test', (0.5, 0, 0)) block_obstacle1.Translation(vm.Vector3D((-5, 2, 3)), False) bbox = block_obstacle1.bounding_box point1 = vm.Point3D((-0.85, 0.44736842, 0.)) point2 = vm.Point3D((-0.285, 0.15, 0.)) point1.Translation(vm.Vector3D((-5, 2, 3)), False) point2.Translation(vm.Vector3D((-5, 2, 3)), False) d = bbox.distance_between_two_points_on_bbox(point1, point2) print(d)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Feb 19 12:34:01 2018 @author: Steven Masfaraud [email protected] """ import volmdlr as vm import volmdlr.primitives3D as p3D sphere = p3D.Sphere(vm.Point3D((0, 0, 0)), 4) cylinder = p3D.Cylinder(vm.Point3D((0, 0, 0)), vm.Vector3D((0, 0, 1)), 0.5, 10) cut = p3D.Cut(sphere, cylinder, name='cutted sphere') model = vm.VolumeModel([('cut', [cut])]) model.FreeCADExport('cut')
# -*- coding: utf-8 -*- """ Testing core module functions """ import math import numpy as npy import volmdlr as vm v2D_1 = vm.Vector2D(3 * npy.random.random(2) - 1.5) v2D_2 = vm.Vector2D(3 * npy.random.random(2) - 1.5) p2D_1 = vm.Point2D(3 * npy.random.random(2) - 1.5) p2D_2 = vm.Point2D(3 * npy.random.random(2) - 1.5) v3D_1 = vm.Vector3D(3 * npy.random.random(3) - 1.5) v3D_2 = vm.Vector3D(3 * npy.random.random(3) - 1.5) p3D_1 = vm.Point3D(3 * npy.random.random(3) - 1.5) p3D_2 = vm.Point3D(3 * npy.random.random(3) - 1.5) # Testing if normalized vector has norm ==1 and is still colinear to original vector v2D_1_normalized = v2D_1.copy() v2D_1_normalized.Normalize() assert math.isclose(v2D_1_normalized.Norm(), 1, abs_tol=1e-9) assert math.isclose(v2D_1_normalized.Dot(v2D_1), v2D_1.Norm(), abs_tol=1e-9) # Testing normal vector normal_v2D_1 = v2D_1.NormalVector() assert math.isclose(normal_v2D_1.Dot(v2D_1), 0, abs_tol=1e-9) normal_unit_v2D_1 = v2D_1.NormalVector(unit=True)
#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), name='straight') # #model_straight=vm.VolumeModel([profile_straight]) profile_helical = primitives3D.HelicalExtrudedProfile(po, xp,
s = volmdlr.Point3D.random(-1, 1, -1, 1, -1, 1) a = volmdlr.edges.Arc3D(s, i, e) ax = a.plot() # for p in a.polygon_points(): # p.plot(ax=ax) s.plot(ax=ax, color='r') e.plot(ax=ax, color='g') i.plot(ax=ax, color='b') arc1 = volmdlr.edges.Arc3D(volmdlr.Point3D(-0.03096, 0.001162, -0.02), volmdlr.Point3D(-0.03120, -0.000400635, -0.02), volmdlr.Point3D(-0.026119083, 0.0, -0.02), volmdlr.Vector3D(0.0, 0.0, 0.001)) ax = arc1.plot() # for p in arc1.polygon_points(): # p.plot(ax=ax) arc1.start.plot(ax=ax, color='r') arc1.end.plot(ax=ax, color='g') arc1.interior.plot(ax=ax, color='b') arc1.center.plot(ax=ax, color='m') print(arc1.center) print(arc1.center - volmdlr.Point3D(-0.030962035803739997, 0.0011626900994054661, -0.02)) print(arc1.center - volmdlr.Point3D(-0.031209642286239472, -0.00040063570451895954, -0.02))
p1=vm.Point2D((0, 0)) p2=vm.Point2D((0.1, 0.)) p3=vm.Point2D((0.1, 0.2)) p4=vm.Point2D((0, 0.1)) p5=vm.Point2D((-0.01, 0.05)) #p6=vm.Point2D((0.1,0.3)) l1=primitives2D.RoundedLineSegments2D([p1, p2, p3, p4], {2: 0.01}, False) l2=vm.Arc2D(p4, p5, p1) c1=vm.Contour2D([l1, l2]) c2=c1.Rotation(vm.Point2D((0,0)),npy.pi,True) c1.MPLPlot() c2.MPLPlot() c3=vm.Contour2D([c1, c2]) c3.MPLPlot() po = vm.Point3D((0, 0, 0)) xp = vm.Vector3D((1, 0, 0)) yp = vm.Vector3D((0, 1, 0)) profile = primitives3D.ExtrudedProfile(po, xp, yp, c1, [], vm.Vector3D((0, 0.1, 0.2))) model = vm.VolumeModel([('', [profile])]) #profile.MPLPlot((0,0,0),(1,0,0),(0,1,0)) #model.MPLPlot() model.FreeCADExport('extrusion2')
def from_file(cls, filename: str, distance_multiplier=0.001): if is_binary(filename): with open(filename, 'rb') as file: stream = KaitaiStream(file) name = stream.read_bytes(80).decode('utf8') # print(name) num_triangles = stream.read_u4le() # print(num_triangles) triangles = [None] * (num_triangles) invalid_triangles = [] for i in range(num_triangles): if i % 5000 == 0: print('reading stl', round(i / num_triangles * 100, 2), '%') normal = vm.Vector3D(stream.read_f4le(), stream.read_f4le(), stream.read_f4le()) # print(n) p1 = vm.Point3D(distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le()) p2 = vm.Point3D(distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le()) p3 = vm.Point3D(distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le(), distance_multiplier * stream.read_f4le()) # print(p1, p2, p3) try: triangles[i] = vmf.Triangle3D(p1, p2, p3) except ZeroDivisionError: invalid_triangles.append(i) stream.read_u2le() # print(abr) if invalid_triangles: print('invalid_triangles number: ', len(invalid_triangles)) for i in invalid_triangles[::-1]: del triangles[i] else: with open(filename, 'r') as file: header = file.readline() name = header[6:] triangles = [] points = [] for line in file.readlines(): if 'vertex' in line: line = line.replace('vertex', '') line = line.lstrip(' ') x, y, z = line.split(' ') points.append( vm.Point3D(distance_multiplier * float(x), distance_multiplier * float(y), distance_multiplier * float(z))) if 'endfacet' in line: try: triangles.append(vmf.Triangle3D(*points)) except ZeroDivisionError: pass points = [] return cls(triangles, name=name)
import volmdlr as vm import volmdlr.primitives3D as primitives3D import math D = 55 * 1e-3 D1 = 47.6 * 1e-3 d = 30 * 1e-3 d1 = 38.3 * 1e-3 B = 13 * 1e-3 n_balls = 13 D_balls = 8 * 1e-3 y_ball0 = (D + d) / 4 theta_b = math.acos((y_ball0 - d1 / 2) / D_balls / 2) x = vm.Vector3D((1, 0, 0)) y = vm.Vector3D((0, 1, 0)) primitives = [] center = vm.Point3D((0, 0, 0)) center_ball1 = vm.Point3D((0, y_ball0, 0)) for i in range(n_balls): angle = i * 2 * math.pi / n_balls center_ball = center_ball1.Rotation(center, x, angle, True) # print(center_ball.vector) primitives.append( primitives3D.Sphere(center_ball, D_balls / 2, 'Ball{}'.format(i + 1))) # inner pi1 = vm.Point2D((-B / 2, d / 2))
import volmdlr import volmdlr.edges import volmdlr.wires import volmdlr.faces p1 = volmdlr.Point3D(0.15, 0.48, 0.5) p2 = volmdlr.Point3D(0.15, 0.1, 0.5) p1s = volmdlr.Point2D(0, 0) p2s = volmdlr.Point2D(0.1, 0) p3s = volmdlr.Point2D(0.2, 0.1) p4s = volmdlr.Point2D(-0.01, 0.05) surface2d = volmdlr.faces.Surface2D( volmdlr.wires.ClosedPolygon2D([p1s, p2s, p3s, p4s]), []) u = volmdlr.Vector3D(0.1, 0.7, -0.5) u.normalize() v = u.deterministic_unit_normal_vector() w = u.cross(v) plane = volmdlr.faces.Plane3D(frame=volmdlr.Frame3D(0.1 * volmdlr.X3D, u, v, w)) face = volmdlr.faces.PlaneFace3D(plane, surface2d) ax = face.plot() p1.plot(ax=ax, color='b') p2.plot(ax=ax, color='g') l1 = volmdlr.edges.LineSegment3D(p1, p1 + w) l2 = volmdlr.edges.LineSegment3D(p2, p2 + w) l1.plot(ax=ax, color='b')
import tutorials.tutorial8_simple_pipe as tuto import plot_data.core as plot_data import volmdlr as vm import networkx as nx lx, ly = 0.5, 0.5 lz = 0.05 frame = vm.Frame3D(vm.Point3D(0, 0, 0), lx * vm.Vector3D(1, 0, 0), ly * vm.Vector3D(0, 1, 0), lz * vm.Vector3D(0, 0, 1)) block = vm.primitives3d.Block(frame) faces = block.faces[0:-1] housing = tuto.Housing(faces, vm.Point3D(0, 0, 0)) p0 = block.faces[-1].outer_contour3d.primitives[0].start p1 = block.faces[-1].outer_contour3d.primitives[2].start # for prim in block.faces[-1].outer_contour3d.primitives: # print(prim.start, prim.end) frame1 = tuto.Frame(p0, p1) p3 = faces[1].bounding_box.center dir3 = faces[1].surface3d.frame.w p4 = faces[2].bounding_box.center dir4 = faces[2].surface3d.frame.w piping1 = tuto.MasterPiping(start=p3, end=p4, direction_start=-dir3, direction_end=dir4, diameter=0.005, length_connector=0.03, minimum_radius=0.01)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Sep 11 23:39:42 2020 @author: Pierrem """ import math import volmdlr as vm import volmdlr.step as vm_step import volmdlr.primitives3d as primitives3d resolution = 0.0010 box = primitives3d.Block(vm.Frame3D(vm.Point3D(0, 0, 0), vm.Vector3D(0.3, 0, 0), vm.Vector3D(0, 0.3, 0), vm.Vector3D(0, 0, 0.3)), alpha=0.6) box_red = primitives3d.Block(vm.Frame3D(vm.Point3D(0, 0, 0), vm.Vector3D(0.4, 0, 0), vm.Vector3D(0, 0.4, 0), vm.Vector3D(0, 0, 0.4)), color=(0.2, 1, 0.4), alpha=0.6) p1_ray = vm.Point3D(-0.15, -0.15, -0.15) p2_ray = vm.Point3D(0.009855980224206917, 0.6250574317556334, -0.1407142090413507) # p1_ray = vm.Point3D(-0.15, -0.12999999999999992, 0.15) # p2_ray = vm.Point3D(0.09377883804318171, 0.17764785706502192, 0.19256693676483136)
# -*- coding: utf-8 -*- """ Created on Thu Apr 2 10:51:54 2020 @author: Mack Pro """ import volmdlr as vm import volmdlr.step import volmdlr.primitives3d as primitives3d import math import matplotlib.pyplot as plt radius = 5e-3 #Choose the radius center = vm.Point3D(0, 0, 0) #Choose the coordinate of the center normal = vm.Vector3D(0, 0, 1) #Choose the normal cylinder = primitives3d.Cylinder(center, normal, radius, length=0.1, name='Cylinder') h = 10e-3 #Height of cylinder angle = 3 * math.pi / 2 #Arc's angle #You have to create a cutting pattern in 2D # center2d = center.to_2d(center, plane.vectors[0], plane.vectors[1]) # segbh = vm.LineSegment2D(center2d, center2d + vm.Point2D((0,h))) # circlestart = vm.LineSegment2D(segbh.points[1], segbh.points[1]+vm.Point2D((angle,0))) # seghb = vm.LineSegment2D(circlestart.points[1],circlestart.points[1]-segbh.points[1])
import matplotlib.pyplot as plt import random import math #### Cyl Cyl rmin, rmax = 10, 100 posmin, posmax = -100, 100 x1, y1, z1 = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 x2, y2, z2 = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 r1, r2 = random.randrange(rmin, rmax, 1)/1000, random.randrange(rmin, rmax, 1)/1000 #Choose the radius c1, c2 = volmdlr.Point3D([x1,y1,z1]), volmdlr.Point3D([x2,y2,z2]) #Choose the coordinate of the center x3, y3, z3 = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 x4, y4, z4 = random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100, random.randrange(posmin, posmax, 1)/100 n1, n2 = volmdlr.Vector3D([x3,y3,z3]), volmdlr.Vector3D([x4,y4,z4]) #Choose the normal 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))
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)) #Plane to place your PlaneFace3D plane = volmdlr.Plane3D.from_normal(c, n) #To do a PlaneFace3D, you need to use contours2D #The first is always the basis, the others are used to cut the basis contours = [volmdlr.Contour2D([outer_circle]), volmdlr.Contour2D([circles[0]]), volmdlr.Contour2D([circles[1]]), volmdlr.Contour2D([circles[2]]), volmdlr.Contour2D([circles[3]]),volmdlr.Contour2D([circles[4]]), volmdlr.Contour2D([circles[5]])] planeface = volmdlr.PlaneFace3D(contours, plane)