sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

grid lines #53

Closed nilsbecker closed 6 years ago

nilsbecker commented 6 years ago

i would like to draw a rectangular grid of lines in the xy-plane with gr3. so far i could not make it work. i tried something like this:

self.mesh = gr3.createsurfacemesh(
                self.segments[0], self.segments[1], 
                xs, ys, zs,
                option=0 * gr3.GR3_SurfaceOption.GR3_SURFACE_FLAT)

and then

gr3.drawsurface(self.mesh)

but this made the entire viewport white.

follow-up: how to draw a cuboid - line grid in 3d?

FlorianRhiem commented 6 years ago

Do you have an image of what you are trying to achieve? gr3.createsurfacemesh would used be for creating a surface plot. A "rectangular grid of lines" sounds more like something built from cylinders (and possibly spheres for the corners) like this:

import gr3
import numpy as np

n_per_axis = 11
n = 2*n_per_axis
positions = np.zeros((n, 3))
positions[:n_per_axis, 0] = np.linspace(-2, 2, n_per_axis)
positions[:n_per_axis, 1] = -2
positions[n_per_axis:, 0] = -2
positions[n_per_axis:, 1] = np.linspace(-2, 2, n_per_axis)
directions = np.zeros((22, 3))
directions[:n_per_axis, 1] = 1
directions[n_per_axis:, 0] = 1
colors = np.ones((22, 3))
radii = 0.01 * np.ones(22)
lengths = 4 * np.ones(22)

gr3.drawcylindermesh(n, positions, directions, colors, radii, lengths)
gr3.export("grid.png", 1000, 1000)

grid

As an aside: 0 * gr3.GR3_SurfaceOption.GR3_SURFACE_FLAT is equal to 0 and therefore gr3.GR3_SurfaceOption.GR3_SURFACE_DEFAULT.

nilsbecker commented 6 years ago

thanks! this looks like what i would like to achieve. i did not think of the cylinder option - i was considering that there must be some sort of 'line' primitive also in 3D with a constant width. the surface plot functions must also use something like that to draw the mesh, no? would a surface plot of a constant-zero function not also work?

the 0 * .. bit was a quick test that i mistakenly copied-and-pasted.

FlorianRhiem commented 6 years ago

GR3 does not support 2D primitives like points and lines, so cylinders or cuboids would be the way to go for a grid. The gr3_createsurfacemesh function creates a 3D mesh based on the x, y and z arrays.

nilsbecker commented 6 years ago

i think i misunderstood what gr3_createsurfacemesh does. i thought it generates a wireframe-like surface representation. but instead it generates a surface mesh which is rendered as a solid surface -- correct?

FlorianRhiem commented 6 years ago

Correct. Together with functions like gr3.surface and gr3.drawsurface it serves as somewhat of an equivalent to gr.surface.