arrows in 3d field plots

182 views
Skip to first unread message

Tevian Dray

unread,
Jan 27, 2019, 11:11:47 AM1/27/19
to sage-support
Can the formatting of arrows in 3d field plots be adjusted?

I'm trying to make rotatable, 3d versions of 2d field plots.
I can get most of what I want with, say:
xy=plot_vector_field3d((x,y,0),(x,-1,1),(y,-1,1),(z,-1,1),colors='black')
show(xy,orientation=(0,0,0,0))
but I'd really like the output to look more like:
plot_vector_field((x,y),(x,-1,1),(y,-1,1))
In other words, more obvious arrowheads. A bigger plot would also help,
to allow setting plot_points to 20 -- the default for 2d.

Are the arrows and/or size (easily) configurable?

Thanks,
Tevian

Tom Judson

unread,
Jan 27, 2019, 12:29:46 PM1/27/19
to sage-support
You can adjust the arrowheads.  Look at http://faculty.sfasu.edu/judsontw/ode/html-20190111/firstlook03.html for some examples.

Tevian Dray

unread,
Jan 27, 2019, 12:53:02 PM1/27/19
to sage-support
Thanks, Tom.  So far as I can tell, your examples use "arrowsize" and "width" to control the arrows.  But so far as I can tell, those parameters have no effect on 3d plots -- yours are all 2d.  Am I missing something?  I'm using the SageMathCell server to test; not sure if that affects the answer.

Tevian

Eric Gourgoulhon

unread,
Jan 28, 2019, 4:54:49 AM1/28/19
to sage-support
Hi,

You can use the plot functionality of vector fields on Euclidean spaces to get better arrowheads:

sage: E.<x,y,z> = EuclideanSpace()
sage: v = E.vector_field((x,y,0))
sage: xy = v.plot(max_range=1, color='black')
sage: show(xy, orientation=(0,0,0,0))

You may also replace the last line by

sage: show(xy, orientation=(0,0,0,0), viewer='threejs')

to use threejs instead of jmol.

More options of the vector field plot functions are described here, especially to control the arrow size are described here:

Best wishes,

Eric.


kcrisman

unread,
Jan 28, 2019, 1:10:30 PM1/28/19
to sage-support


On Monday, January 28, 2019 at 4:54:49 AM UTC-5, Eric Gourgoulhon wrote:
Hi,

You can use the plot functionality of vector fields on Euclidean spaces to get better arrowheads:

sage: E.<x,y,z> = EuclideanSpace()
sage: v = E.vector_field((x,y,0))
sage: xy = v.plot(max_range=1, color='black')
sage: show(xy, orientation=(0,0,0,0))

You may also replace the last line by

sage: show(xy, orientation=(0,0,0,0), viewer='threejs')

to use threejs instead of jmol.

Wow, that should probably be in the plot documentation (and/or even replace some of the current functionality). 

Tevian Dray

unread,
Jan 28, 2019, 1:44:00 PM1/28/19
to sage-s...@googlegroups.com
>> You can use the plot functionality of vector fields on Euclidean
>> spaces to get better arrowheads:

Excellent! Thank you!

>> You may also replace the last line by
>> sage: show(xy, orientation=(0,0,0,0), viewer='threejs')

Yes, I had to do that -- jmol froze my browser. I haven't had a chance
yet to debug that problem, nor to experiment with parameters. But
threejs unfortunately appears to ignore the orientation parameter, which
defeats the purpose. And is there a way to disable the perspective view?
I want the 2d-view seen from above to look like a 2d vector field, with
the arrows sitting exactly on top of each other; the perspective tries
to show them all. Again, I haven't had a chance yet myself to debug or
explore parameters...

Thanks again,
Tevian

Tevian Dray

unread,
Jan 31, 2019, 12:52:10 AM1/31/19
to sage-s...@googlegroups.com
>> You can use the plot functionality of vector fields on
>> Euclidean spaces to get better arrowheads:

OK; I can get jmol to work with some browsers, although it is painfully slow. But the results are very nice.

>> And is there a way to disable the perspective view?
>> I want the 2d-view seen from above to look like a with the
>> 2d vector field, arrows sitting exactly on top of each other;
>> the perspective tries to show them all.

I reported this issue with threejs, but it's also present with jmol. Yes, it's possible to eliminate the perspective view interactively, by right-clicking, and unchecking "Perspective Depth" in the Style menu. But I'd like to place these images in final form on a webpage, so I'm looking for a way to encode jmol settings in either Sage or HTML. Is this possible?

Finally, is there a simple mechanism to enable Sage to plot vector fields with singularities, such as a pole at the origin? I've had no luck yet trying to plot something like:
E.vector_field((-y/(x^2+y^2),x/(x^2+y^2)))
I've tried piecing together nonsingular domains, although I'm possibly not doing it correctly. But there is surely a more elegant solution, such as cutting off the vector field at some maximum magnitude.

Thanks,
Tevian

Eric Gourgoulhon

unread,
Jan 31, 2019, 5:15:37 PM1/31/19
to sage-support
Le jeudi 31 janvier 2019 06:52:10 UTC+1, Tevian Dray a écrit : 
>> You can use the plot functionality of vector fields on
>> Euclidean spaces to get better arrowheads:

OK; I can get jmol to work with some browsers, although it is painfully slow.  But the results are very nice.


Hopefully, some day threejs will replace jmol as the default 3d viewer:


Finally, is there a simple mechanism to enable Sage to plot vector fields with singularities, such as a pole at the origin?  I've had no luck yet trying to plot something like:
  E.vector_field((-y/(x^2+y^2),x/(x^2+y^2)))
I've tried piecing together nonsingular domains, although I'm possibly not doing it correctly.  But there is surely a more elegant solution, such as cutting off the vector field at some maximum magnitude.

The cut off should definitely be added to the plot method of vector fields, among many other improvements to be done...
Meanwhile, you can define a subdomain of E, U say, where the vector field is everywhere regular and plot the restriction of the vector field to U. For your example, U can be E minus the disk x^2+y^2 <= 0.01:

sage: E.<x,y> = EuclideanSpace()
sage: v = E.vector_field((-y/(x^2+y^2),x/(x^2+y^2)))
sage: U = E.open_subset('U', coord_def={E.cartesian_coordinates(): x^2+y^2>0.01})
sage: v.restrict(U).plot(max_range=1, scale=0.2)

In the above code,  "coord_def" stands for the coordinate definition of the open subset U and "v.restrict(U)" is the restriction of v to U.

Best wishes,

Eric.
 

Tevian Dray

unread,
Feb 1, 2019, 12:14:14 AM2/1/19
to sage-s...@googlegroups.com
> Hopefully, some day threejs will replace jmol as the default 3d viewer:
> https://trac.sagemath.org/ticket/22408

Good, although I reiterate that it does not appear to respect the
orientation flag.

> Meanwhile, you can define a subdomain of E, U say, where the vector field
> is everywhere regular and plot the restriction of the vector field to U.
> For your example, U can be E minus the disk x^2+y^2 <= 0.01: ...

Yes, that works perfectly; thank you.

Now to try to track down how to set jmol parameters in a web page...

Tevian

Tevian Dray

unread,
Feb 2, 2019, 1:45:02 PM2/2/19
to sage-s...@googlegroups.com
>> Now to try to track down how to set jmol parameters in a web page...

I've given up for now on using Sage for this project, as it turns out
that Geogebra can accomplish what I need out of the box. For reference,
the resulting webpage is:
http://math.oregonstate.edu/bridge/ideas/fields
Happy to revisit this choice as we start to port these applets into our
online book over the next couple of years.

Thanks to all for their suggestions.
Tevian

Reply all
Reply to author
Forward
0 new messages