Esempio n. 1
0
 def test_surface_torus(self):
     # default torus
     surf = SurfaceFactory.torus(1, 3)
     start = surf.start()
     end = surf.end()
     # check a 13 evaluation points of v-evaluation (around the z-axis)
     v = np.linspace(start[1], end[1], 13)
     # check minor-circle u=0 (outmost ring)
     x = surf.evaluate(0, v)
     for pt in np.array(x[0, :, :]):
         self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 4 * 4)  # check radius=4
         self.assertAlmostEqual(pt[2], 0)  # check height=0
     # check minor-circle u=pi (innermost ring)
     x = surf.evaluate(pi, v)
     for pt in np.array(x[0, :, :]):
         self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 2 * 2)  # check radius=2
         self.assertAlmostEqual(pt[2], 0)  # check height=0
     # check minor-circle u=pi/2 (topmost ring)
     x = surf.evaluate(pi / 2, v)
     for pt in np.array(x[0, :, :]):
         self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1], 3 * 3)  # check radius=3
         self.assertAlmostEqual(pt[2], 1)  # check height=1
     # check minor-circle u=3*pi/2 (mid-evaluation)
     x = surf.evaluate(3 * pi / 4, v)
     for pt in np.array(x[0, :, :]):
         self.assertAlmostEqual(pt[0] * pt[0] + pt[1] * pt[1],
                                (3 - 1.0 / sqrt(2))**2)  # check radius=3-1/sqrt(2)
         self.assertAlmostEqual(pt[2], 1.0 / sqrt(2))  # check height=1/sqrt(2)
Esempio n. 2
0
    def torus(self):
        dim      = int(     self.read_next_non_whitespace().strip())
        r2       = float(   next(self.fstream).strip())
        r1       = float(   next(self.fstream).strip())
        center   = np.array(next(self.fstream).split(), dtype=float)
        z_axis   = np.array(next(self.fstream).split(), dtype=float)
        x_axis   = np.array(next(self.fstream).split(), dtype=float)
        select_out=         next(self.fstream).strip() != '0' # I have no idea what this does :(
        param_u  = np.array(next(self.fstream).split(), dtype=float)
        param_v  = np.array(next(self.fstream).split(), dtype=float)
        swap     =          next(self.fstream).strip() != '0'

        result = SurfaceFactory.torus(minor_r=r1, major_r=r2, center=center, normal=z_axis, xaxis=x_axis)
        result.reparam(param_u, param_v)
        if(swap):
            result.swap()
        return result
Esempio n. 3
0
# Examples on how to write geometries to file
#
# Author:    Kjetil Andre Johannessen
# Institute: Norwegian University of Science and Technology (NTNU)
# Date:      March 2016
#

from sys import path
path.append('../')
from splipy.io import G2, STL
import splipy.surface_factory as surfaces

# create a NURBS torus
torus = surfaces.torus(minor_r=1, major_r=4)


# STL files are tessellated linear triangles. View with i.e. meshlab
with STL('torus.stl') as my_file:
    my_file.write(torus, n=(50, 150)) # specify resolution of 50x150 evaluation pts


# G2 files are native GoTools (http://www.sintef.no/projectweb/geometry-toolkits/gotools/)
with G2('torus.g2') as my_file:
    my_file.write(torus)