sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.31k stars 451 forks source link

Add custom scaling feature for vectors in plot_vector_field3d() as available in ​VectorField.plot() #34038

Open ea007ec0-dfc6-4661-b6de-0fd1ed448353 opened 2 years ago

ea007ec0-dfc6-4661-b6de-0fd1ed448353 commented 2 years ago

plot_vector_field3d() lacks user defined scaling. By default the plotted vectors in the field are auto scaled (from 0 to 1) by using maximum length vector in the plotting domain. It is a very nice thing to auto scale like this as it avoids possible overprint of vectors with those ahead of them. But sometimes if user needs them to be scaled to a desired factor say 1 (no scaling) then for those situations we propose availability of user defined scaling as available in ​VectorField.plot(). This can be achieved by following modifications in src/sage/plot/plot3d/plot_field3d.py:

  1. Add a new keyword scale='auto' to plot_vector_field3d() which can take any real number as scaling factor. Anything other than real number is ignored and auto scaling is performed. Default value 'auto' has nothing to do other than being a non-real quantity, a string, telling it to go with default auto scaling. We wish auto scaling be the default.
def plot_vector_field3d(functions, xrange, yrange, zrange,
                        plot_points=5, colors='jet', center_arrows=False,
                        scale='auto', **kwds):
  1. Modify the existing
    max_len = max(v.norm() for v in vectors)
    scaled_vectors = [v/max_len for v in vectors]

into

    if scale in RR:
        scaled_vectors = [v*scale for v in vectors]
    else: # For `scale` is anything other than real number
        max_len = max(v.norm() for v in vectors)
        scaled_vectors = [v/max_len for v in vectors]

Component: graphics

Keywords: plot 3d vector field, plot_vector_field3d()

Author: Vincent Delecroix, Niranjana K M

Issue created by migration from https://trac.sagemath.org/ticket/34038

ea007ec0-dfc6-4661-b6de-0fd1ed448353 commented 2 years ago

Changed author from Vincent, Niranjana to Vincent Delecroix, Niranjana K M

ea007ec0-dfc6-4661-b6de-0fd1ed448353 commented 2 years ago

Changed keywords from plot, vector, field3d to plot 3d vector field, plot_vector_field3d()

DaveWitteMorris commented 2 years ago
comment:4

A ticket should not be set to "needs review" until it has a git branch that incorporates the proposed changes.

kcrisman commented 2 years ago
comment:5

This isn't a bad idea at all - and your comment about 2d plots maybe implies #2922 is already done? But it would also need a significant amount of documentation to show how it can be used.

See also:

ea007ec0-dfc6-4661-b6de-0fd1ed448353 commented 2 years ago
comment:6

No #2922 is not done. By default the vectors are normalized and scaling option is not provided. Scaling is available in VectorField.plot() which is a part of sage manifolds but is a bit slow due to wide capabilities of sage manifolds and its methods.

kcrisman commented 2 years ago
comment:7

Scaling is available in VectorField.plot() which is a part of sage manifolds but is a bit slow due to wide capabilities of sage manifolds and its methods.

I see. So really we currently have two ways of getting vector fields - the plot methods and the manifold methods. It might be nice to unify those somehow, though (obviously) not in this ticket.

ea007ec0-dfc6-4661-b6de-0fd1ed448353 commented 2 years ago
comment:8

Replying to @kcrisman:

I see. So really we currently have two ways of getting vector fields - the plot methods and the manifold methods. It might be nice to unify those somehow, though (obviously) not in this ticket.

See Eric's comments in:

https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/aJhd3vDtAgAJ

https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/2FQTQrn3AgAJ

https://groups.google.com/g/sage-devel/c/tMH1RZNyC9s/m/gKoZ5nkCAwAJ