示例#1
0
vx = RegressedPixelGridSpline(U.T, grid_sparse.resolution, grid_sparse.extent)
vy = RegressedPixelGridSpline(V.T, grid_sparse.resolution, grid_sparse.extent)
for i, j in itertools.product(range(X.shape[0]), range(X.shape[1])):
    p = np.array([X[i, j], Y[i, j]])
    vxx = vx.gradient(p)[0]
    vyy = vy.gradient(p)[1]
    div[i, j] = vxx + vyy

for i in range(iterations):
    if ROWS * COLS == 1 and i < iterations - 1:
        continue
    print("plot..")
    p_source = grid_sparse.world_to_grid(x_source)
    p = grid_sparse.grid_to_world(p_source)
    phi = phi.T
    phi = hd.distance(U, V, div, 1. / N).T
    renderer.set_drawing_axis(i)
    renderer.draw_ws_obstacles()
    renderer.draw_ws_point(p, color='r', shape='o')
    renderer.background_matrix_eval = False
    renderer.draw_ws_img(phi, interpolate="bicubic", color_style=plt.cm.hsv)
    f = RegressedPixelGridSpline(phi, grid_sparse.resolution,
                                 grid_sparse.extent)
    for i, j in itertools.product(range(X.shape[0]), range(X.shape[1])):
        g = f.gradient(np.array([X[i, j], Y[i, j]]))
        g /= np.linalg.norm(g)
        U[i, j] = g[0]
        V[i, j] = g[1]
    renderer._ax.quiver(X, Y, U, V, units='width')
renderer.show()
示例#2
0
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION,   ARISING OUT OF OR IN    CONNECTION WITH THE USE   OR
# PERFORMANCE OF THIS SOFTWARE.
#
#                                        Jim Mainprice on Sunday June 13 2018

import demos_common_imports
from pyrieef.geometry.workspace import *
from pyrieef.geometry.diffeomorphisms import *
from pyrieef.rendering.workspace_planar import WorkspaceDrawer

env = EnvBox(dim=np.array([2., 2.]))
box = Box(origin=np.array([-.5, -.5]), dim=np.array([.5, .5]))
segment = Segment(origin=np.array([.4, -.5]), orientation=0.2)
circle = Circle(origin=np.array([.5, .5]), radius=0.2)
ellipse = Ellipse(a=0.5, b=0.3)
polygon = hexagon(.33)
# polygon = ConvexPolygon()
workspace = Workspace(env)
workspace.obstacles.append(box)
workspace.obstacles.append(segment)
workspace.obstacles.append(circle)
workspace.obstacles.append(polygon)
# workspace.obstacles.append(ellipse)
viewer = WorkspaceDrawer(workspace, wait_for_keyboard=True)
sdf = SignedDistanceWorkspaceMap(workspace)
viewer.draw_ws_obstacles()
viewer.background_matrix_eval = True
viewer.draw_ws_background(sdf, nb_points=200)
viewer.show_once()
    Y1[k] = g[0]
    Y2[k] = g[1]
    k += 1

# Store the Data in a LWR (Linear Weighted Regression)
# object where dimension of the vector field are being abstracted
f = LWR(2, 2)
f.X = [X_data, X_data]
f.Y = [Y1, Y2]
f.D = [np.eye(2), np.eye(2)]
f.ridge_lambda = [.1, .1]

# Querries the regressed function f
# And then draws the interolated field in red and original points in black
X_int, Y_int = workspace.box.meshgrid(30)
U_int, V_int = np.zeros(X_int.shape), np.zeros(Y_int.shape)
for i, j in itertools.product(range(X_int.shape[0]), range(X_int.shape[1])):
    g = f(np.array([X_int[i, j], Y_int[i, j]]))
    U_int[i, j] = g[0]
    V_int[i, j] = g[1]

renderer = WorkspaceDrawer(workspace)
renderer.set_drawing_axis(i)
renderer.draw_ws_obstacles()
renderer.draw_ws_point([0, 0], color='r', shape='o')
renderer.background_matrix_eval = True
renderer.draw_ws_background(sdf, color_style=plt.cm.Blues)
renderer._ax.quiver(X, Y, U, V, units='width', color='k')
renderer._ax.quiver(X_int, Y_int, U_int, V_int, units='width', color='r')
renderer.show()