ChristopherChudzicki / math3d-react

A user-friendly 3d graphing calculator for the web. Create, share, and animate 3d mathematical scenes.
https://www.math3d.org
Mozilla Public License 2.0
245 stars 34 forks source link

Adding a movable vector gradient #381

Open soegaard opened 7 months ago

soegaard commented 7 months ago

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 commented 7 months ago

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:

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 commented 7 months ago

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 commented 7 months ago

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.