Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    def Volume(self):
        areas = [c.Area() for c in self.contours2D]
        # Maximum area is main surface, others cut into it
        sic = list(npy.argsort(areas))[::-1]  # sorted indices of contours
        p1 = self.axis_point.PlaneProjection3D(self.plane_origin, self.x,
                                               self.y)
        if self.axis_point.PointDistance(p1) != 0:
            raise NotImplementedError
        p1_2D = p1.To2D(self.axis_point, self.x, self.y)
        p2_3D = self.axis_point + volmdlr.Point3D(self.axis.vector)
        p2 = p2_3D.PlaneProjection3D(self.plane_origin, self.x, self.y)
        if p2_3D.PointDistance(p2) != 0:
            raise NotImplementedError
        p2_2D = p2_3D.To2D(self.plane_origin, self.x, self.y)
        axis_2D = volmdlr.Line2D(p1_2D, p2_2D)
        com = self.contours2D[sic[0]].CenterOfMass()
        rg = axis_2D.PointDistance(com)
        volume = areas[sic[0]] * rg

        for i in sic[1:]:
            com = self.contours2D[i].CenterOfMass()
            rg = axis_2D.PointDistance(com)
            volume -= areas[i] * rg

        return self.angle * volume
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
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')
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
import volmdlr.edges as vme
import matplotlib.pyplot as plt

degree = 3
points = [
    vm.Point2D(0, 0),
    vm.Point2D(1, 1),
    vm.Point2D(2, 0),
    vm.Point2D(3, 0)
]
bezier_curve2d = vme.BezierCurve2D(degree=degree,
                                   control_points=points,
                                   name='bezier curve 1')
_, ax = plt.subplots()
bezier_curve2d.plot(ax=ax)
[p.plot(ax=ax) for p in points]

degree = 3
points = [
    vm.Point3D(0, 0, 0),
    vm.Point3D(1, 1, 2),
    vm.Point3D(2, 1, 1),
    vm.Point3D(3, 0, 4)
]
bezier_curve3d = vme.BezierCurve3D(degree=degree,
                                   control_points=points,
                                   name='bezier curve 1')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
bezier_curve3d.plot(ax=ax)
[p.plot(ax=ax) for p in points]
Ejemplo n.º 12
0
# -*- 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
Ejemplo n.º 13
0
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))
pi2 = vm.Point2D((-B / 2, d1 / 2))
pi3 = vm.Point2D((-0.5 * D_balls * math.sin(theta_b), d1 / 2))
pi4 = vm.Point2D((0, y_ball0 - D_balls / 2))
pi5 = vm.Point2D((0.5 * D_balls * math.sin(theta_b), d1 / 2))
Ejemplo n.º 14
0
from automotive.models.workflows import seat_analysis_workflow
from automotive.models import cockpit, back_seat

import volmdlr as vm
# seat_analysis_workflow.plot_jointjs()

seat_analysis = seat_analysis_workflow.run({0:1000,
                              2:vm.Point3D(0, 0.3, 0.),
                              3: back_seat,
                              4: vm.Point2D(0, 0.),
                              6:cockpit})

seat_analysis.output_value.babylonjs()
Ejemplo n.º 15
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 23 18:06:45 2018

@author: steven
"""

import volmdlr as vm
import numpy as npy
i = vm.Point3D((1, 0, 0))
e = i.Rotation(vm.o3D, vm.z3D, 1)
s = i.Rotation(vm.o3D, vm.z3D, -3.5)

a = vm.Arc3D(s, i, e)
assert a.angle == 4.5

# Random arc
i = vm.Point3D(npy.random.random(3))
e = vm.Point3D(npy.random.random(3))
s = vm.Point3D(npy.random.random(3))

a = vm.Arc3D(s, i, e)
a.MPLPlot()
Ejemplo n.º 16
0
@author: Mack Pro
"""

import volmdlr as vm
import volmdlr.edges as vme
import matplotlib.pyplot as plt
import random

##### cas 9 arc/arc

mini, maxi = -5, 5
rad_min, rad_max = 1, 3

pt1 = vm.Point3D.random(mini, maxi, mini, maxi, mini, maxi)
rad1 = random.randint(rad_min, rad_max)
start1, interior1, end1 = pt1, pt1 + vm.Point3D(
    0, -rad1, rad1), pt1 + vm.Point3D(0, -2 * rad1, 0)
arc1 = vme.Arc3D(start1, interior1, end1)

pt2 = vm.Point3D.random(mini, maxi, mini, maxi, mini, maxi)
rad2 = random.randint(rad_min, rad_max)
start2, interior2, end2 = pt2, pt2 + vm.Point3D(
    -2 * rad2, 0, 0), pt2 + vm.Point3D(-rad2, rad2, 0)

# TODO testcase to make robust
try:
    arc2 = vme.Arc3D(start2, interior2, end2)

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    pt1.plot(ax=ax)
    arc1.plot(ax=ax)
Ejemplo n.º 17
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 11 15:16:33 2018

@author: steven
"""

import volmdlr as vm
import volmdlr.primitives3d as primitives3d
import volmdlr.wires as wires
import numpy as npy
import random
import matplotlib.pyplot as plt
p1 = vm.Point3D(0, 0, 0)
p2 = vm.Point3D(-0.150, 0, 0)
p3 = vm.Point3D(-0.150, 0.215, 0)
p4 = vm.Point3D(-0.150, 0.215, -0.058)
p5 = vm.Point3D(-0.175, 0.186, -0.042)

points = [p1, p2, p3, p4, p5]
radius = {1: 0.015, 2: 0.020, 3: 0.005}

current_point = p5
#points = [p1, p2]
#radius = {1: 0.010}
for i in range(6):
    current_point += vm.Point3D.random(-0.1, 0.3, -0.1, 0.3, -0.1, 0.3)
    points.append(current_point)
    radius[4 + i] = 0.01 + 0.03 * random.random()
#print(radius)
#shell1 = volumemodel.primitives[1] # LA BOITE
#shell2 = volumemodel.shells[2] # LE BLOCK
#shell2 = volumemodel.shells[2] # LE CMO
#shell3 = volumemodel.shells[3] # UN PETIT BOUT SE TROUVANT A L'INTERIEUR DU CMO
#shell4 = volumemodel.shells[4] # UN PETIT BOUT SE TROUVANT A L'INTERIEUR DU CMO

#del volumemodel.shells[4]
#del volumemodel.shells[3]

# volumemodel.babylonjs()
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')
Ejemplo n.º 19
0
# -*- 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(
Ejemplo n.º 20
0
#!/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)
Ejemplo n.º 21
0
#!/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)
Ejemplo n.º 22
0
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
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
Ejemplo n.º 23
0
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),
                                                name='straight')
#
#model_straight=vm.VolumeModel([profile_straight])

profile_helical = primitives3D.HelicalExtrudedProfile(po,
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Minimum distance line between two lines
"""

import volmdlr as vm
import numpy as npy

p11 = vm.Point3D(npy.random.random(3))
p12 = vm.Point3D(npy.random.random(3))
p21 = vm.Point3D(npy.random.random(3))
p22 = vm.Point3D(npy.random.random(3))

l1 = vm.Line3D(p11, p12)
l2 = vm.Line3D(p21, p22)

pmd1, pmd2 = l1.MinimumDistancePoints(l2)

u = p12 - p11  # vector of line1
v = p22 - p21  # vector of line2
w = pmd2 - pmd1

print(u.Dot(w), v.Dot(w))

m = vm.VolumeModel([('', [l1, l2, pmd1, pmd2])])
m.MPLPlot()
Ejemplo n.º 25
0
import random

### Cas arc/LS

mini, maxi = -5, 5

pt1 = vm.Point3D.random(mini, maxi, mini, maxi, mini, maxi)
pt2 = vm.Point3D.random(mini, maxi, mini, maxi, mini, maxi)
ptmid = (pt1 + pt2) / 2
pt_midmid = pt1 + (pt2 - pt1) / 4
pt_midmid2 = pt2 + (pt1 - pt2) / 4
LS1 = vme.LineSegment3D(pt1, pt2)

pt = vm.Point3D.random(mini, maxi, mini, maxi, mini, maxi)
radius = 2
start, interior, end = pt, pt + vm.Point3D(
    0, -radius, radius), pt + vm.Point3D(0, -radius, -radius)
arc = vme.Arc3D(start, interior, end)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
pt1.plot(ax=ax)
pt2.plot(ax=ax, color='r')
LS1.plot(ax=ax)
start.plot(ax=ax, color='g')
interior.plot(ax=ax, color='b')
end.plot(ax=ax, color='y')
arc.plot(ax=ax)
ptmid.plot(ax=ax)

pta1, pta2 = arc.minimum_distance_points_line(LS1)
pta1.plot(ax=ax, color='m')
Ejemplo n.º 26
0
# Random arc
i = volmdlr.Point3D.random(-1, 1, -1, 1, -1, 1)
e = volmdlr.Point3D.random(-1, 1, -1, 1, -1, 1)
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 -
Ejemplo n.º 27
0
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 = {
    1: 0.03,
    2: 0.01,
    3: 0.07,
    4: 0.01
}  #, 5: 0.07, 6: 0.02, 7: 0.03, 8: 0.04}
rl1 = primitives3D.OpenedRoundedLineSegments3D(pts1,
                                               radius1,
                                               adapt_radius=True,
                                               name='wire1')
sweep1 = primitives3D.Sweep(contour1, rl1, name='pipe1')

pts2 = []
for k in range(nb_point2):
Ejemplo n.º 28
0
Test for importing geometry from volmdlr
"""

import hydraulic as hy
from hydraulic.fluids import water

import volmdlr as vm
import volmdlr.primitives3d as primitives3d

T_liq = 20
dP = 1e5
dQ = 0.005

diameter = 0.010

p1 = vm.Point3D(0, 0, 0)
p2 = vm.Point3D(0.2, 0, 0)
p3 = vm.Point3D(0.2, 0.1, 0)
p4 = vm.Point3D(0.2, 0.1, 0.08)
p5 = vm.Point3D(0.4, 0, 0)

points = [p1, p2, p3, p4, p5]

rl = primitives3d.OpenRoundedLineSegments3D(points, {
    1: 0.03,
    2: 0.01,
    3: 0.02
},
                                            adapt_radius=True)

pipes = [
Ejemplo n.º 29
0
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()
Ejemplo n.º 30
0
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))
pt11 = volmdlr.Point3D((0.02, 0.24, 0.25))
pt12 = volmdlr.Point3D((0.6, 0.24, 0.20))