예제 #1
0
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg

from compas_vol.primitives import VolSphere, VolBox
from compas_vol.combinations import Union,Subtraction
from compas.geometry import Sphere, Box, Frame
from compas.rpc import Proxy

s = VolSphere(Sphere((0, 0, 0), 6))
b = VolBox(Box(Frame.worldXY(), 10, 10, 10), 1.5)
u = Union(s, b)
t = Subtraction(b, s)

p = Proxy('compas_vol.utilities')
#p.stop_server()
#p = Proxy('compas_vol.utilities')

bounds = ((-25,25,100), (-25,25,100), (-25,25,100))
vs,fs = p.get_vfs_from_tree(str(t), bounds, 1.0)

mesh = rg.Mesh()
for v1, v2, v3 in vs:
    mesh.Vertices.Add(v1, v2, v3)
for f in fs:
    if len(set(f))>2:
        mesh.Faces.AddFace(f[0], f[1], f[2])
mesh.Compact()
mesh.Normals.ComputeNormals()

a = mesh
b = [rs.CreatePoint(v1,v2,v3) for v1, v2, v3 in vs]
예제 #2
0
        return da + self.f * db

    def get_distance_numpy(self, x, y, z):
        """
        vectorized distance function
        """
        da = self.a.get_distance_numpy(x, y, z)
        db = self.b.get_distance_numpy(x, y, z)
        return da + self.f * db


if __name__ == "__main__":
    from compas_vol.primitives import VolSphere, VolBox
    from compas.geometry import Box, Frame, Point, Sphere

    s = Sphere(Point(2, 3, 0), 7)
    b = Box(Frame.worldXY(), 20, 15, 10)
    vs = VolSphere(s)
    vb = VolBox(b, 2.5)
    f = Overlay(vs, vb, 0.2)
    print(f)
    for y in range(-15, 15):
        s = ''
        for x in range(-30, 30):
            d = f.get_distance((x * 0.5, y, 0))
            if d < 0:
                s += 'x'
            else:
                s += '.'
        print(s)
예제 #3
0
import numpy as np
import matplotlib.pyplot as plt

from compas_vol.primitives import VolSphere
from compas_vol.analysis import Gradient
from compas.geometry import Point, Sphere

s = Sphere(Point(1, 2, 3), 4)
vs = VolSphere(s)

g = Gradient(vs)
print(vs.get_distance(Point(4, 5, 6)))
print(g.get_gradient(Point(5, 2, 3)))

x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
d = g.get_gradient_numpy(x, y, z)

plt.quiver(x, y, d[:, :, 0, 1], d[:, :, 0, 2])
plt.axis('equal')
plt.show()