Skip to content

VectorsGraphic #560

@kushalkolar

Description

@kushalkolar

Easy to do with PointsMarkerMaterial and the geometry. One thing I need do figure out is how to do the point rotations in 3D in model space.

with #913 :

see: #908 (comment)

# get uniform x, y positions
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))

# positions of each vector as [n_points, 2] array
data = np.column_stack([X.ravel(), Y.ravel()])

# vectors, u and v are x and y components
U = np.cos(X)
V = np.sin(Y)

# angle of each vector
rotations = np.atan2(U, V)
# ravel so it maps `data` index -> rotation
rotations = rotations.ravel()

# sizes is magnitude
# ravel so it maps `data` index -> size
sizes = np.linalg.norm(np.dstack([U, V]), axis=-1).ravel() * 10

fig = fpl.Figure(size=(700, 600))

fig[0, 0].add_scatter(
    data, 
    point_rotation_mode="vertex",
    point_rotations=rotations, 
    sizes=sizes,
    markers="custom",
    uniform_marker=True,
    custom_sdf=vector_sdf,
    
)

fig.show()

Maybe an API like:

subplot.add_vector_field(
    positions=[n_vectors, 3], # position of vector in x, xy, or xyz
    vectors=[n_vectors, 3], # indicates direction vector is pointing
    shape=..., # option from a few predefined common shapes, uses some predefined sdfs
    shape_options={...}, # an optional dict of some arrow options in the predfined sdf
    custom_shape=... # custom sdf
    colors=..., # maps data index -> colors, can be uniform
    uniform_colors=...,
    cmap=...,
    cmap_transform=...,
    size_factor=..., # scales sizes by this factor
    size_space=..., # usual size space option, world, screen, model,
)

see what options other libs have too

The proposed API above will only require 2 new graphic features. One buffer manager to represent the vector directions which is actually a geo rotations buffer, and a uniform for the shape.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions