Exemplo n.º 1
0
    def test_ellipse(self):
        # test (x/1)^2 + (y/5)^2 = 1
        c = cf.ellipse(1, 5)
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x, y = pt
            self.assertAlmostEqual((x / 1)**2 + (y / 5)**2, 1)

        # test (x-.3/1)^2 + (y-6/5)^2 = 1
        c = cf.ellipse(1, 5, center=(.3, 6))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x, y = pt
            self.assertAlmostEqual(((x - .3) / 1)**2 + ((y - 6) / 5)**2, 1)

        # test ellipse along x=y axis
        c = cf.ellipse(1, 2, xaxis=(1, 1))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x, y = pt
            s = 1 / sqrt(2)
            self.assertAlmostEqual(
                ((s * x + s * y) / 1)**2 + ((s * x - s * y) / 2)**2, 1)

        # test ellipse in 3D
        c = cf.ellipse(1, 2, normal=(0, 1, 0), xaxis=(1, 0, 1))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x, y, z = pt
            s = 1 / sqrt(2)
            self.assertAlmostEqual(
                ((s * x + s * z) / 1)**2 + ((s * x - s * z) / 2)**2, 1)
Exemplo n.º 2
0
    def test_ellipse(self):
        # test (x/1)^2 + (y/5)^2 = 1
        c = CurveFactory.ellipse(1,5)
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x,y = pt
            self.assertAlmostEqual((x/1)**2 + (y/5)**2, 1)

        # test (x-.3/1)^2 + (y-6/5)^2 = 1
        c = CurveFactory.ellipse(1,5, center=(.3, 6))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x,y = pt
            self.assertAlmostEqual(((x-.3)/1)**2 + ((y-6)/5)**2, 1)

        # test ellipse along x=y axis
        c = CurveFactory.ellipse(1,2, xaxis=(1,1))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x,y = pt
            s = 1/sqrt(2)
            self.assertAlmostEqual(((s*x + s*y)/1)**2 + ((s*x - s*y)/2)**2, 1)

        # test ellipse in 3D
        c = CurveFactory.ellipse(1,2, normal=(0,1,0), xaxis=(1,0,1))
        t = np.linspace(c.start(0), c.end(0), 25)
        for pt in c.evaluate(t):
            x,y,z = pt
            s = 1/sqrt(2)
            self.assertAlmostEqual(((s*x + s*z)/1)**2 + ((s*x - s*z)/2)**2, 1)
Exemplo n.º 3
0
    def ellipse(self):
        dim   = int(     self.read_next_non_whitespace().strip())
        r1    = float(   next(self.fstream).strip())
        r2    = float(   next(self.fstream).strip())
        center= np.array(next(self.fstream).split(), dtype=float)
        normal= np.array(next(self.fstream).split(), dtype=float)
        xaxis = np.array(next(self.fstream).split(), dtype=float)
        param = np.array(next(self.fstream).split(), dtype=float)
        reverse =        next(self.fstream).strip() != '0'

        result = CurveFactory.ellipse(r1=r1, r2=r2, center=center, normal=normal, xaxis=xaxis)
        result.reparam(param)
        if reverse:
            result.reverse()
        return result