def volmdlr_primitives(self): primitives = [] cockpit_frame = vm.Frame3D(self.cockpit_position, vm.X3D, vm.Y3D, vm.Z3D) front_right_seat_frame = cockpit_frame.copy() front_right_seat_frame.origin.y = -cockpit_frame.origin.y primitives.extend( self.cockpit.seat.volmdlr_primitives(frame=front_right_seat_frame)) xrs, zrs = self.rear_seat_position rear_seat_frame = vm.Frame3D(vm.Point3D(xrs, 0, zrs), vm.X3D, vm.Y3D, vm.Z3D) primitives.extend( self.rear_seat.volmdlr_primitives(frame=rear_seat_frame)) if self.passengers and self.passengers[0]: npassengers = len(self.passengers) primitives.extend( self.cockpit.volmdlr_primitives( frame=cockpit_frame, seat_x_setting=self.passengers[0].seat_x_setting, seat_z_setting=self.passengers[0].seat_z_setting)) primitives.extend( self.passengers[0].volmdlr_primitives(cockpit_frame)) if npassengers >= 2: primitives.extend(self.passengers[1].volmdlr_primitives( front_right_seat_frame)) else: primitives.extend( self.cockpit.volmdlr_primitives(frame=cockpit_frame)) return primitives
def volmdlr_primitives(self, frame=vm.OXYZ, seat_x_setting=0., seat_z_setting=0): primitives = self.seat.volmdlr_primitives(frame, seat_x_setting, seat_z_setting) xsw, zsw = self.steering_wheel_position # ysw = self.left_front_seat_position.y wsw = frame.u.rotation(vm.O3D, frame.v, (self.steering_wheel_tilt)) usw = frame.v.cross(wsw) steering_wheel_frame = vm.Frame3D( frame.origin + vm.Point3D(xsw, 0., zsw), usw, frame.v, wsw) steering_wheel = faces.ToroidalSurface3D(steering_wheel_frame, 0.5*self.steering_wheel_diameter, 0.017) \ .rectangular_cut(0, vm.TWO_PI, 0, vm.TWO_PI) steering_wheel.name = 'Steering wheel' primitives.append(steering_wheel) xp, zp = self.pedals_position # yp = self.left_front_seat_position.y wp = vm.Z3D.rotation(vm.O3D, vm.Y3D, math.radians(-60)) up = vm.Y3D.cross(wp) pedals_frame = vm.Frame3D(frame.origin + vm.Point3D(xp, 0., zp), up, frame.v, wp) pedals = faces.Plane3D(pedals_frame).rectangular_cut( -0.04, 0.04, -0.1, 0.1) pedals.name = 'Pedals' primitives.append(pedals) return primitives
def volmdlr_primitives(self): primitives = self.interior.volmdlr_primitives() front_left_wheel_frame = vm.Frame3D( vm.Point3D(0, 0.5 * self.track, 0.5 * self.front_wheel.tyre.diameter), vm.Y3D, -vm.X3D, vm.Z3D) primitives.extend( self.front_wheel.volmdlr_primitives(frame=front_left_wheel_frame)) front_right_wheel_frame = vm.Frame3D( vm.Point3D(0, -0.5 * self.track, 0.5 * self.front_wheel.tyre.diameter), -vm.Y3D, vm.X3D, vm.Z3D) primitives.extend( self.front_wheel.volmdlr_primitives(frame=front_right_wheel_frame)) rear_left_wheel_frame = vm.Frame3D( vm.Point3D(-self.wheelbase, 0.5 * self.track, 0.5 * self.rear_wheel.tyre.diameter), vm.Y3D, -vm.X3D, vm.Z3D) primitives.extend( self.rear_wheel.volmdlr_primitives(frame=rear_left_wheel_frame)) rear_right_wheel_frame = vm.Frame3D( vm.Point3D(-self.wheelbase, -0.5 * self.track, 0.5 * self.rear_wheel.tyre.diameter), -vm.Y3D, vm.X3D, vm.Z3D) primitives.extend( self.rear_wheel.volmdlr_primitives(frame=rear_right_wheel_frame)) if self.outside_xz_contour: outside_xz_contour2 = self.outside_xz_contour.offset(0.01) if outside_xz_contour2.area() < self.outside_xz_contour.area(): primitives.append( p3d.ExtrudedProfile(-0.4 * self.track * vm.Y3D, vm.X3D, vm.Z3D, self.outside_xz_contour, [outside_xz_contour2], vm.Y3D * 0.8 * self.track, alpha=0.5)) else: primitives.append( p3d.ExtrudedProfile(-0.4 * self.track * vm.Y3D, vm.X3D, vm.Z3D, outside_xz_contour2, [self.outside_xz_contour], vm.Y3D * 0.8 * self.track, alpha=0.5)) return primitives
def volmdlr_primitives(self, frame=vm.OXYZ, x_setting=0., z_setting=0): cushion_contour = self.cushion_contour().translation( vm.Point2D(x_setting, z_setting)) cushion = p3d.ExtrudedProfile(frame.origin - 0.5 * self.width * frame.v, frame.u, frame.w, cushion_contour, [], self.width * frame.v, name='cushion', color=(0.2, 0.2, 0.2)) backrest_contour = self.backrest_contour().translation( vm.Point2D(x_setting, z_setting)) backrest = p3d.ExtrudedProfile(frame.origin - 0.5 * self.width * frame.v, frame.u, frame.w, backrest_contour, [], self.width * frame.v, color=(0.2, 0.2, 0.2), name='backrest') headrest_contour = self.headrest_contour().translation( vm.Point2D(x_setting, z_setting)) headrest = p3d.ExtrudedProfile(frame.origin - 0.25 * self.width * frame.v, frame.u, frame.w, headrest_contour, [], 0.5 * self.width * frame.v, color=(0.2, 0.2, 0.2), name='headrest') floor = faces.Plane3D(vm.Frame3D(frame.origin-self.floor_height*vm.Z3D, vm.X3D, vm.Y3D, vm.Z3D))\ .rectangular_cut(0.25, 1, -0.5*self.width, 0.5*self.width) roof = faces.Plane3D(vm.Frame3D(frame.origin+self.roof_height*vm.Z3D, vm.X3D, vm.Y3D, vm.Z3D))\ .rectangular_cut(-0.15, 0.15, -0.5*self.width, 0.5*self.width) primitives = [cushion, backrest, headrest, floor, roof] return primitives
#!/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)
#!/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)
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') l2.plot(ax=ax, color='g') i1 = face.linesegment_intersections(l1) if i1: i1[0].plot(ax=ax, color='r')
volumemodel.babylonjs(page_name='debug') # volumemodel_copy.babylonjs_from_meshes(page_name='debug') #%% origin = vm.Point3D((1, 0.1, 0.6)) u = vm.y3D v = vm.z3D w = vm.x3D u.Normalize() v.Normalize() w.Normalize() #u = vm.y3D #v = vm.z3D #w = vm.x3D frame = vm.Frame3D(origin, u, v, w) print('fram_mapping copy=False') shell0.frame_mapping(frame, 'old', False) print('Success') #print('Transaliton copy=False') #shell0.Translation(vm.Vector3D((1,0.5,0)), False) #print('Success') #print('frame_mapping copy=True') #volumemodel.primitives[1] = shell1.frame_mapping(frame, 'old', True) #print('Success') #print('Translation copy=True') #volumemodel.primitives[1] = shell0.Translation(vm.Vector3D((-1,1,2)), True) #print('Success')
@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( (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)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jan 27 10:54:45 2020 @author: masfaraud """ import volmdlr as vm import volmdlr.primitives3D as primitives3D block1 = primitives3D.Block(vm.Frame3D(vm.O3D.copy(), vm.X3D.copy(), vm.Y3D.copy(), vm.Z3D.copy()), color=(0.8, 0.1, 0.1), alpha=0.5, name='Block 1') block2 = block1.copy() block2.color = [0.1, 0.1, 0.8] block2.name = 'Block 2' f1 = vm.OXYZ.copy() f2 = f1.Rotation(vm.Z3D, 0.1, copy=True) f2.Translation(0.1 * vm.X3D, copy=False) f3 = f2.Rotation(vm.Z3D, 0.1, copy=True) f3.Translation(0.1 * vm.X3D, copy=False) f4 = f3.Rotation(vm.Z3D, 0.1, copy=True)
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 -*- """ """ import volmdlr as vm import volmdlr.faces as faces R = 0.32 alpha = 0.2 cs = vm.faces.ConicalSurface3D( vm.Frame3D(vm.Point3D.random(-0.1, 0.1, -0.1, 0.2, -0.2, 0.1), vm.X3D, vm.Y3D, vm.Z3D), alpha) cf = cs.rectangular_cut(-0.01, 1.3, 0., 0.3) cf.surface2d.plot() cf.babylonjs(debug=True, use_cdn=False)
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 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
import volmdlr as vm import volmdlr.edges as vme import volmdlr.wires as vmw import volmdlr.faces as vmf import volmdlr.primitives3d as p3d sphere = vmf.SphericalSurface3D(vm.Frame3D(vm.O3D, vm.X3D, vm.Y3D, vm.Z3D), 0.3) sphere.plot() # sphere.babylonjs() face = sphere.rectangular_cut(0, 2.5, 0, 0.5) face.babylonjs() face.plot() # Try to generate a sphere from revoltion radius = 0.03 p1 = vm.Point2D(0, -radius) p2 = vm.Point2D(radius, 0.) p3 = vm.Point2D(0, radius) arc = vme.Arc2D(p1, p2, p3) line = vme.LineSegment2D(p3, p1) contour = vmw.Contour2D([arc, line]) sphere_revolution = p3d.RevolvedProfile(vm.X3D, vm.X3D, vm.Y3D, contour, vm.X3D, vm.Y3D, angle=1.3) sphere_revolution.babylonjs()
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)) 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]
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 tutorials.tutorial5_piping as tuto import plot_data.core as plot_data import volmdlr as vm f1 = vm.Frame3D(vm.Point3D(0.05, 0.1, 0), vm.Vector3D(1, 0, 0), vm.Vector3D(0, 1, 0), vm.Vector3D(0, 0, 1)) p1 = vm.faces.Plane3D(f1) s1 = vm.faces.Surface2D(outer_contour=vm.wires.ClosedPolygon2D([vm.Point2D(-0.05, -0.1), vm.Point2D(0.05, -0.1), vm.Point2D(0.05, 0.1), vm.Point2D(-0.05, 0.1)]), inner_contours=[]) face1 = vm.faces.OpenShell3D([vm.faces.PlaneFace3D(surface3d=p1, surface2d=s1)]) face1.color = (92/255, 124/255, 172/255) face1.alpha = 1 f2 = vm.Frame3D(vm.Point3D(0.05, 0.1, 0.005), vm.Vector3D(1, 0, 0), vm.Vector3D(0, 0, 1), vm.Vector3D(0, 1, 0)) p2 = vm.faces.Plane3D(f2) s2 = vm.faces.Surface2D(outer_contour=vm.wires.ClosedPolygon2D([vm.Point2D(-0.05, -0.005), vm.Point2D(0.05, -0.005), vm.Point2D(0.05, 0.005), vm.Point2D(-0.05, 0.005)]), inner_contours=[]) face2 = vm.faces.OpenShell3D([vm.faces.PlaneFace3D(surface3d=p2, surface2d=s2)]) face2.color = (92/255, 124/255, 172/255) face2.alpha = 1 vol = vm.core.VolumeModel([face1, face2]) vol.babylonjs() housing = tuto.Housing(faces=[face1, face2], origin=vm.Point3D(0, 0, 0)) housing.babylonjs()
list_component_hat.append(rooftop) # m = vm.VolumeModel(all_solid+[bottom]) # m.babylonjs(debug=True) # m = vm.VolumeModel(all_solid+[sides,bottom, belt]) # m.babylonjs(debug=True) # m = vm.VolumeModel(all_solid+list_component_hat) # m.babylonjs(debug=True) # m = vm.VolumeModel(all_solid+[sides,bottom, belt]+list_component_hat) # m.babylonjs() primitives = all_solid + [bottom, sides, belt] + list_component_hat nb_primitives = len(primitives) away_frame = vm.Frame3D(vm.Point3D((100, 100, 100)), vm.X3D, vm.Y3D, vm.Z3D) steps = [ [vm.OXYZ] * nb_components + [away_frame] * (nb_primitives - nb_components), [vm.OXYZ] * (nb_components + 1) + [away_frame] * (nb_primitives - nb_components - 1), [vm.OXYZ] * (nb_components + 3) + [away_frame] * (nb_primitives - nb_components - 3), [vm.OXYZ] * (nb_components + 3 + len(primitives_floor[0])) + [away_frame] * (nb_primitives - nb_components - 3 - len(primitives_floor[0])), [vm.OXYZ] * (nb_components + 3 + len(primitives_floor[0]) + len(primitives_floor[1])) + [away_frame] * (nb_primitives - nb_components - 3 - len(primitives_floor[0]) - len(primitives_floor[1])), [vm.OXYZ] * nb_primitives ] volmod = vm.MovingVolumeModel(primitives, steps) volmod.babylonjs()