Beispiel #1
0
    def plot(self):

        myplot = bp.Plotting((bp.PlottingPlotly()))
        myplot.plot_surface_3d(self.surfapprox.surfz, poles=False)
        myplot.plot_surface_3d(self.surfapprox2.surfz, poles=False)
        #myplot.scatter_3d(X, Y, Z)
        myplot.show()  # view
Beispiel #2
0
    def test_surface_intersection(self):

        control_points = [60, 60]
        sapp = SurfApprox(control_points)
        app = sapp.approx
        myplot = bp.Plotting((bp.PlottingPlotly()))
        myplot.plot_surface_3d(sapp.surfz, poles=False)
        #myplot.scatter_3d(app._xy_points[:, 0], app._xy_points[:, 1], app._z_points)
        myplot.show()  # view
Beispiel #3
0
def plot_cmp(a_grid, b_grid):
    plt = bs_plot.Plotting()
    plt.scatter_3d(a_grid[:, :, 0], a_grid[:, :, 1], a_grid[:, :, 2])
    plt.scatter_3d(b_grid[:, :, 0], b_grid[:, :, 1], b_grid[:, :, 2])
    plt.show()

    diff = b_grid - a_grid
    plt.scatter_3d(a_grid[:, :, 0], a_grid[:, :, 1], diff[:, :, 0])
    plt.scatter_3d(a_grid[:, :, 0], a_grid[:, :, 1], diff[:, :, 1])
    plt.scatter_3d(a_grid[:, :, 0], a_grid[:, :, 1], diff[:, :, 2])
    plt.show()
Beispiel #4
0
def verify_approximation(func, surf):
    # Verification.
    # Evaluate approximation and the function on the same grid.

    nu = 4 * surf.u_basis.size
    nv = 4 * surf.v_basis.size
    V_grid, U_grid = np.meshgrid(np.linspace(0.0, 1.0, nu), np.linspace(0.0, 1.0, nv))
    xy_probe = np.stack([U_grid.ravel(), V_grid.ravel()], axis=1)
    # xyz_approx = surf.eval_xy_array(xy_probe).reshape(-1, 3)
    #
    z_func_eval = np.array([func([u, v]) for u, v in xy_probe], dtype=float)
    xyz_func = np.concatenate((xy_probe, z_func_eval[:, None]), axis=1).reshape(-1, 3)

    #plot_cmp(xyz_approx, xyz_func)
    plt = bs_plot.Plotting()
    plt.plot_surface_3d(surf.make_full_surface(), (nu, nv), poles=False)
    plt.scatter_3d(xyz_func[:,0], xyz_func[:,1], xyz_func[:,2])
    plt.show()
Beispiel #5
0
def test_surface_intersection(plane_coefficients1, control_points_1, length1): #plane_coefficients1

        print(plane_coefficients1, control_points_1, length1)


        #plane_coefficients1 = np.array([-1, 1, -1, 7])
        plane_coefficients2 = np.array([2, -1, -1, 3])

        def cosx(x):
            return math.cos(3 * x)

        length2 = [5, 7]
        control_points_2 = [10, 11]
        samples = [200, 200]


        sapp2 = SurfApprox(plane_coefficients2, length2, samples, control_points_2, cosx)


        myplot = bp.Plotting((bp.PlottingPlotly()))
        myplot.plot_surface_3d(sapp2.surfz, poles=False)
        myplot.show() # view
Beispiel #6
0
    def test_hull_and_box(self):
        points = np.random.randn(1000000, 2)

        print()
        start = time.perf_counter()
        for i in range(1):
            hull = bs_approx.convex_hull_2d(points)
        end = time.perf_counter()
        print("\nConvex hull of 1M points: {} s".format(end - start))

        start = time.perf_counter()
        for i in range(10):
            quad = bs_approx.min_bounding_rect(hull)
        end = time.perf_counter()
        print("Min area bounding box: {} s".format(end - start))
        return

        plt = bs_plot.Plotting()
        plt.scatter_2d(points[:, 0], points[:, 1])
        plt.plot_2d(hull[:, 0], hull[:, 1])
        box_lines = np.concatenate((quad, quad[0:1, :]), axis=0)
        plt.plot_2d(box_lines[:, 0], box_lines[:, 1])
        plt.show()
Beispiel #7
0
from bgem.bspline import bspline as bs, bspline_plot as bp
import numpy as np
import math

import matplotlib.pyplot as plt

plotting = bp.Plotting()
#plotting = bp.Plotting(bp.PlottingMatplot())


class TestSplineBasis:
    def test_find_knot_interval(self):
        """
        test methods:
        - make_equidistant
        - find_knot_interval
        """
        eq_basis = bs.SplineBasis.make_equidistant(2, 100)
        assert eq_basis.find_knot_interval(0.0) == 0
        assert eq_basis.find_knot_interval(0.001) == 0
        assert eq_basis.find_knot_interval(0.01) == 1
        assert eq_basis.find_knot_interval(0.011) == 1
        assert eq_basis.find_knot_interval(0.5001) == 50
        assert eq_basis.find_knot_interval(1.0 - 0.011) == 98
        assert eq_basis.find_knot_interval(1.0 - 0.01) == 99
        assert eq_basis.find_knot_interval(1.0 - 0.001) == 99
        assert eq_basis.find_knot_interval(1.0) == 99

        knots = np.array([
            0, 0, 0, 0.1880192, 0.24545785, 0.51219762, 0.82239001, 1., 1., 1.
        ])
Beispiel #8
0
 def test_plot_3d(self):
     self.plotting_3d(bp.Plotting(bp.PlottingMatplot()))
     self.plotting_3d(bp.Plotting(bp.PlottingPlotly()))
Beispiel #9
0
    def plot_extrude(self):
        #fig1 = plt.figure()

        #ax1 = fig1.gca(projection='3d')



        def function(x):
            return math.sin(x[0]*4) * math.cos(x[1] * 4)

        def function2(x):
            return math.cos(x[0]*4) * math.sin(x[1] * 4)

        def function3(x):
            return (-x[0] + x[1] + 4 + 3 + math.cos(3 * x[0]))

        def function4(x):
            return (2 * x[0] - x[1] + 3 + math.cos(3 * x[0]))

        u1_int = 4
        v1_int = 4
        u2_int = 4
        v2_int = 4

        u_basis = bs.SplineBasis.make_equidistant(2, u1_int) #10
        v_basis = bs.SplineBasis.make_equidistant(2, v1_int) #15
        u2_basis = bs.SplineBasis.make_equidistant(2, u2_int) #10
        v2_basis = bs.SplineBasis.make_equidistant(2, v2_int) #15
        poles = bs.make_function_grid(function, u1_int + 2, v1_int + 2) #12, 17
        surface_extrude = bs.Surface((u_basis, v_basis), poles)

        myplot = bp.Plotting((bp.PlottingPlotly()))
        #myplot.plot_surface_3d(surface_extrude, poles = False)
        poles2 = bs.make_function_grid(function2,  u2_int + 2, v2_int + 2) #12, 17
        surface_extrude2 = bs.Surface((u2_basis, v2_basis), poles2)
        #myplot.plot_surface_3d(surface_extrude2, poles=False)

        m = 100
        fc = np.zeros([m * m, 3])
        fc2 = np.empty([m * m, 3])
        a = 5
        b = 7
        #print(fc)

        for i in range(m):
            for j in range(m):
                #print([i,j])
                x = i / m * a
                y = j / m * b
                z = function3([x, y])
                z2 = function4([x, y])
                fc[i + j * m, :] = [x, y, z]
                fc2[i + j * m, :] = [x, y, z2]

        #print(fc)

        #gs = bs.GridSurface(fc.reshape(-1, 3))
        #gs.transform(xy_mat, z_mat)
        #approx = bsa.SurfaceApprox.approx_from_grid_surface(gs)




        approx = bsa.SurfaceApprox(fc)
        approx2 = bsa.SurfaceApprox(fc2)
        surfz = approx.compute_approximation(nuv=np.array([11, 26]))
        surfz2 = approx2.compute_approximation(nuv=np.array([20, 16]))
        #surfz = approx.compute_approximation(nuv=np.array([3, 5]))
        #surfz2 = approx2.compute_approximation(nuv=np.array([2, 4]))
        surfzf = surfz.make_full_surface()
        surfzf2 = surfz2.make_full_surface()


        myplot.plot_surface_3d(surfzf, poles=False)
        myplot.plot_surface_3d(surfzf2, poles=False)

        #return surface_extrude, surface_extrude2, myplot
        return surfzf, surfzf2, myplot