예제 #1
0
    def test_spelling(self):
        mesh = BarycentricMesh([{0, 1}, {0, 1}])
        values = np.array([[0, 1, 2, 3]])

        mesh.get_input_grid()
        self.assertEquals(mesh.get_input_size(), 2)
        self.assertEquals(mesh.get_num_mesh_points(), 4)
        self.assertEquals(mesh.get_num_interpolants(), 3)
        self.assertTrue((mesh.get_mesh_point(0) == [0., 0.]).all())
        points = mesh.get_all_mesh_points()
        self.assertEqual(points.shape, (2, 4))
        self.assertTrue((points[:, 3] == [1., 1.]).all())
        self.assertEquals(mesh.Eval(values, (0, 0))[0], 0)
        self.assertEquals(mesh.Eval(values, (1, 0))[0], 1)
        self.assertEquals(mesh.Eval(values, (0, 1))[0], 2)
        self.assertEquals(mesh.Eval(values, (1, 1))[0], 3)
예제 #2
0
    def test_surf(self):
        mesh = BarycentricMesh([{0, 1}, {0, 1}])
        values = np.array([[0, 1, 2, 3]])

        import matplotlib.pyplot as plt
        from mpl_toolkits.mplot3d import Axes3D
        fig = plt.figure()
        ax = fig.add_subplot(111, projection='3d')

        X, Y = np.meshgrid(list(mesh.get_input_grid()[0]),
                           list(mesh.get_input_grid()[1]))
        Z = np.reshape(values, X.shape)

        ax.plot_surface(X, Y, Z)
        ax.set_xlabel('x')
        ax.set_ylabel('y')
예제 #3
0
파일: math_test.py 프로젝트: weiqiao/drake
 def test_spelling(self):
     mesh = BarycentricMesh([{0, 1}, {0, 1}])
     values = np.array([[0, 1, 2, 3]])
     grid = mesh.get_input_grid()
     self.assertIsInstance(grid, list)
     self.assertEqual(len(grid), 2)
     self.assertIsInstance(grid[0], set)
     self.assertEqual(len(grid[0]), 2)
     self.assertEqual(mesh.get_input_size(), 2)
     self.assertEqual(mesh.get_num_mesh_points(), 4)
     self.assertEqual(mesh.get_num_interpolants(), 3)
     self.assertTrue((mesh.get_mesh_point(0) == [0., 0.]).all())
     points = mesh.get_all_mesh_points()
     self.assertEqual(points.shape, (2, 4))
     self.assertTrue((points[:, 3] == [1., 1.]).all())
     self.assertEqual(mesh.Eval(values, (0, 0))[0], 0)
     self.assertEqual(mesh.Eval(values, (1, 0))[0], 1)
     self.assertEqual(mesh.Eval(values, (0, 1))[0], 2)
     self.assertEqual(mesh.Eval(values, (1, 1))[0], 3)
예제 #4
0
"""Shows examples using math utilities."""

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

from pydrake.math import BarycentricMesh

# Plot a surface using BarycentricMesh.
mesh = BarycentricMesh([{0, 1}, {0, 1}])
values = np.array([[0, 1, 2, 3]])

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

X, Y = np.meshgrid(list(mesh.get_input_grid()[0]),
                   list(mesh.get_input_grid()[1]))
Z = np.reshape(values, X.shape)

ax.plot_surface(X, Y, Z)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()