Ejemplo n.º 1
0
def get_norms(surf, timestep_limit):
    # create a 2D bezier curve
    curve = BSpline.Curve()
    curve.degree = 3

    ctrl_points = [[np.random.uniform(0, 0.2), np.random.uniform(0, 0.2)],
                   [np.random.uniform(0, 0.5), np.random.uniform(0, 0.5)],
                   [np.random.uniform(0.25, 0.75), np.random.uniform(0.25, 0.75)],
                   [np.random.uniform(0.5, 0.75), np.random.uniform(0.5, 0.75)],
                   [np.random.uniform(0.8, 1), np.random.uniform(0.8, 1.0)]]

    curve.set_ctrlpts(ctrl_points)
    curve.knotvector = utilities.generate_knot_vector(curve.degree, len(curve.ctrlpts))
    curve.sample_size = timestep_limit
    curve.evaluate()
    points_c = curve.evalpts
    norms = normal(surf, points_c)
    angles = []  # pitch, yaw
    traj = []  # x,y,z
    for i in range(len(norms)):
        nu = np.array(norms[i][1])
        yaw = 180.0*np.arctan2(np.abs(nu[1]), np.abs(nu[0]))/np.pi
        ca = np.linalg.norm(nu[0:2])
        pitch = 180.0*np.arctan2(nu[2], ca)/np.pi
        angles.append([pitch, yaw])
        point = np.array(norms[i][0])
        traj.append(np.array([point[0], point[1], point[2], pitch, yaw]))
    return traj, norms, curve
Ejemplo n.º 2
0
 def normal_array(self, us, vs):
     if geomdl is not None:
         uv_coords = list(zip(list(us), list(vs)))
         spline_normals = np.array(
             operations.normal(self.surface, uv_coords))[:, 1, :]
         return spline_normals
Ejemplo n.º 3
0
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, 6)

# Set evaluation delta
surf.delta = 0.05

# Evaluate surface
surf.evaluate()

# Evaluate surface tangent and normal vectors
uv_vals = [[0.1, 0.1], [0.65, 0.25], [0.9, 0.7], [0.2, 0.9]]
surftans = [[] for _ in range(len(uv_vals))]
surfnorms = [[] for _ in range(len(uv_vals))]

for idx, uv in enumerate(uv_vals):
    surftans[idx] = operations.tangent(surf, uv, normalize=True)
    surfnorms[idx] = operations.normal(surf, uv, normalize=True)

# Prepare points for plotting
surfpts = np.array(surf.evalpts)
tangent_vectors = np.array(surftans)
normal_vectors = np.array(surfnorms)

# Start plotting of the surface and the control points grid
fig = plt.figure(figsize=(10.67, 8), dpi=96)
ax = Axes3D(fig)

# Plot surface points
ax.plot_trisurf(surfpts[:, 0],
                surfpts[:, 1],
                surfpts[:, 2],
                color='xkcd:gold',
Ejemplo n.º 4
0
# Set degrees
surf.degree_u = 3
surf.degree_v = 3

# Set control points
surf.set_ctrlpts(
    *exchange.import_txt("ex_surface02.cpt", two_dimensional=True))

# Set knot vectors
surf.knotvector_u = utilities.generate_knot_vector(surf.degree_u, 6)
surf.knotvector_v = utilities.generate_knot_vector(surf.degree_v, 6)

# Set evaluation delta
surf.delta = 0.025

# Evaluate surface
surf.evaluate()

# Plot the control point grid and the evaluated surface
vis_comp = VisPlotly.VisSurface()
surf.vis = vis_comp
surf.render()

# Evaluate surface tangent and normal at the given u and v
uv = [0.2, 0.9]
surf_tangent = operations.tangent(surf, uv)
surf_normal = operations.normal(surf, uv)

# Good to have something here to put a breakpoint
pass
Ejemplo n.º 5
0
curve.evaluate()

#
# Multiple vector evaluation after v3.0.7
#

# List of parametric coordinates to be evaluated
u_list = (0.0175, 0.075, 0.375, 0.535, 0.65, 0.85, 0.975)

# Evaluate tangents, normals and binormals, respectively
curvetans = [[] for _ in range(len(u_list))]
curvenorms = [[] for _ in range(len(u_list))]
curvebinorms = [[] for _ in range(len(u_list))]
for idx, u in enumerate(u_list):
    curvetans[idx] = operations.tangent(curve, u, normalize=True)
    curvenorms[idx] = operations.normal(curve, u, normalize=True)
    curvebinorms[idx] = operations.binormal(curve, u, normalize=True)

#
# Control Points, Curve and Tangent Vector Plotting using Matplotlib
#

# Arrange control points and evaluated curve points for plotting
ctrlpts = np.array(curve.ctrlpts)
curvepts = np.array(curve.evalpts)

# Convert tangent, normal and binormal vector lists into NumPy arrays
ctarr = np.array(curvetans)
cnarr = np.array(curvenorms)
cbnarr = np.array(curvebinorms)