Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a movable vector gradient #381

Open
soegaard opened this issue Dec 13, 2023 · 3 comments
Open

Adding a movable vector gradient #381

soegaard opened this issue Dec 13, 2023 · 3 comments

Comments

@soegaard
Copy link

It would be great to have "gradient" in the list of objects.
Both a gradient in a fixed point as well as in a movable point would be great.

https://en.wikipedia.org/wiki/Gradient

@ChristopherChudzicki
Copy link
Owner

Thanks for this suggestion! My take on this is:

  1. Calculating the gradient is a very common mathematical task and should be easy
    • Math3d has this (diff), though the documentation + discoverability should definitely be improved.
  2. Visualizing the gradient can be done with common graphical objects (arrows).
    • Math3d has this—the Vector or Vector Field objects, depending if you want one or many arrows.

Users should be able to combine the above two primitives, along with variable sliders, to produce nice visualizations of the gradient.

For example, something like this: https://www.math3d.org/derivatives

Note: There is absolutely work that could be done to improve this process / make easier for users:

  • diff(f,X,Y) isn't super discoverable. It's used in some of the examples, where it's mentioned that this is the total derivative (aka gradient) but I don't think any examples use it on a function from R^N -> R.
  • In particular, diff(f,X,Y) is a 2d vector, and plotting it in 3d is currently pretty clunky. It should be easier to use 2d vectors in 3d. (Maybe implicitly 2d vectors have 3rd component zero).
  • A 2d slider would be cool.
  • This sort of gradient visualization is common enough it should probably be one of the builtin examples available in top right.

Heads-up: The above improvements all sound good to me. I probably won't include them in math3d soon. Currently I'm focusing on a (backwards-compatible) rewrite of the site (https://github.com/christopherChudzicki/math3d-next)

@soegaard
Copy link
Author

Hi Christopher,

Due to your many hints, I have almost succeed in make a surface
showing the gradient along a curve (embeded in the surface).

https://www.math3d.org/VHQkBLxps

The part that happens on the surface works fine.

The tail property of the vektor was used to glue the vector to the curve.

However, I could not figure out how to turn a two-dimensional vector
from diff(f,x,y) into a three-dimensional one [with 0 as z].

How can I add a coordinate to a vector?
[It's the last field in the main folder at the left.]

Then I found pdiff in "derivatives.js" but something is wrong.
The vector in the xy-plane and the vector on the surface doesn't match.

@ChristopherChudzicki
Copy link
Owner

How can I add a coordinate to a vector?
[It's the last field in the main folder at the left.]

I agree this is a bit awkward. [pdff(f,x,y,1), pdfiff(f,x,y,2), 0] is a reasonable approach. I do think this should be easier than it is.

but something is wrong.
The vector in the xy-plane and the vector on the surface doesn't match.

I'm not sure what you want "the vector on the surface" to be (what you have graphed is a tangent vector to the curve c(t)).

The gradient of the surface f(x,y) will be a two-dimensional vector; 0 is a natural z-component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants