Contributing a 3D plotter

191 views
Skip to first unread message

Patricio Whittingslow

unread,
Jan 16, 2021, 11:21:53 AM1/16/21
to gonum-dev
Hello fellow gonum gophers. I've been interested in adding a 3D plotter to the gonum/plot suite. So far I've used fogleman/ln library and have gotten good results.

This is my Go 3D plot implementation: https://github.com/soypat/plot3

I'm wondering if implementing the Plotter interface would be a viable option or if I should design a new Plotter3 interface based on the Plotter interface. If so, are there any lessons you've learned? 

Dan Kortschak

unread,
Jan 16, 2021, 4:35:13 PM1/16/21
to gonu...@googlegroups.com
I think there is potential utility from this, but it's a matter of
figuring out a good API and also how it will fit with the current API
in a way that doesn't make the 2D use more difficult.

My thoughts.

Using ln looks like a good basis, but I would suggest that rather than
rendering to png or svg, you use the ln.Paths to make a vg.Path. From
what I can see in ln, this looks pretty straightforward and means that
all of the gonum/plot backends become available.

The plot.New function by default gives you axes and assumes a 2D plot,
so a distinct type that handles 3D would be appropriate. I'm not sure
where this would go and there has historically been resistance to
inclusion of a 3D plot system. A 3D plot type could borrow extensively
from the current plotter, reusing a lot of the existing infrastructure
for axes and labels, but would also need to essentially duplicate a
fair bit as well; as you say it would need a 3D plotter interface. On
this basis, if it were added it should probably go in a new package
(plot3?).

An important thing to consider it how it will interact with the vggio
back end since with 3D plots there is even more reason to include
interactive plots (rotation and zoom very helpful in 3D plots). Seb is
the person to discuss this with.

Dan


Dan Kortschak

unread,
Jan 16, 2021, 4:52:44 PM1/16/21
to gonu...@googlegroups.com
Something that I missed is how to handle labels. The size of text is
not handled by ln (it doesn't handle text at all). Text size is a
valuable visual hint for depth (shading can be used for this as well),
so it would be important to be able to have access to label depth for
point associated with points in a plot that matches how ln sees a scene
(including plane clipping - ln.Scene.Visible will help with this). This
is available through the Z field.

Dan


Sebastien Binet

unread,
Jan 16, 2021, 5:47:46 PM1/16/21
to Dan Kortschak, gonu...@googlegroups.com
hi,
I think that now we have the vggio backend, we can indeed envision a 3D
plotter that would provide interactivity (zooming, paning, etc...)
making the 3D plotter carry its own weight.

developping the plot interactivity tools and API would also be useful
for gonum/plot-2d :)

so, yeah, I am all for it.

(BTW: welcome Patricio, and thanks for your interest in Gonum)

-s

Patricio Whittingslow

unread,
Jan 17, 2021, 10:46:37 AM1/17/21
to gonum-dev
Alright, so summed up we have the following:
* 3D plotting is not a bad idea and could be a part of gonum's future!
* Probably will require new function  plot.New3D() Plotter3 based on the original Plotter

 I'm unsure on what you mean by handling labels. If I am to use Parts of gonum's plotter interface, won't that be solved there? What is label depth?

Sebastien Binet

unread,
Jan 17, 2021, 11:29:12 AM1/17/21
to pwhitt...@itba.edu.ar, gonu...@googlegroups.com
I suspect what Dan is alluding to is the handling of text at different 'z' depths that, somehow, need to be scaled up or down depending on whether the text is closer or farther from the 'camera'.

Perusing (very quickly) the ln API, I didn't notice a dedicated function or method to do that. (But I may have overlooked it).


-------- Original Message --------
--
You received this message because you are subscribed to the Google Groups "gonum-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gonum-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gonum-dev/d1f52287-c8e6-423a-8520-99e6a769a45fn%40googlegroups.com.

Patricio Whittingslow

unread,
Jan 17, 2021, 11:58:00 AM1/17/21
to gonum-dev
The ln library needs a camera position and orientation to render paths as 2D. With that position  and the text position (both XYZ) one can find the distance and adjust text scale accordingly. 

That said, I'm unsure this is a needed feature for the plotter. The 3D plotters I know (pgfplots, Matlab) do not adjust text size depending on distance to 'camera'.

Dan Kortschak

unread,
Jan 17, 2021, 3:18:31 PM1/17/21
to gonu...@googlegroups.com
On Sun, 2021-01-17 at 16:29 +0000, Sebastien Binet wrote:
> I suspect what Dan is alluding to is the handling of text at
> different 'z' depths that, somehow, need to be scaled up or down
> depending on whether the text is closer or farther from the 'camera'.

Yes, this is what I meant.

> Perusing (very quickly) the ln API, I didn't notice a dedicated
> function or method to do that. (But I may have overlooked it).

It would need to be built with the vg API; either fading the colour or
scaling the text (ln has no text handling).

Dan



Dan Kortschak

unread,
Jan 17, 2021, 3:18:38 PM1/17/21
to Patricio Whittingslow, gonum-dev
On Sun, 2021-01-17 at 08:57 -0800, Patricio Whittingslow wrote:
> The ln library needs a camera position and orientation to render
> paths as 2D. With that position and the text position (both XYZ) one
> can find the distance and adjust text scale accordingly.

Yes, it's trivial to implement.

> That said, I'm unsure this is a needed feature for the plotter. The
> 3D plotters I know (pgfplots, Matlab) do not adjust text size
> depending on distance to 'camera'.

I think we can do better though. Given that the plot type will hold the
camera and will do the work of plotting, we can ask it to take into
account text depth. It may well be that the scaling factor defaults to
zero and there is no depth-related hinting, but the depth hints do
markedly clarify plots.

Dan


Dan Kortschak

unread,
Jan 17, 2021, 3:18:42 PM1/17/21
to gonum-dev
On Sun, 2021-01-17 at 07:46 -0800, Patricio Whittingslow wrote:
> * Probably will require new function plot.New3D() Plotter3 based on
> the original Plotter

I think that more likely plot3.Plot would be better, but we can discuss
that.

Dan


Randall O'Reilly

unread,
Jan 18, 2021, 12:18:12 AM1/18/21
to Patricio Whittingslow, gonum-dev
You might want to look at GoGi for a Go-native GUI that supports 3D and 2D intermixed: https://github.com/goki/gi -- it would be easy to impl an interactive 3D plot viewer there. We already have a 2D interactive gonum plot viewer, that takes the SVG from gonum and renders it: https://github.com/emer/etable (eplot). I guess for output to SVG it would require a full 3D -> 2D rendering framework anyway? But maybe having GPU-accelerated 3D would be useful for the interactive mode in any case?

- Randy
> To view this discussion on the web visit https://groups.google.com/d/msgid/gonum-dev/8feb1ba5-091c-46d8-9fbc-adb9ac1f956cn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages