How do we go about computing the gradient of a vector in Godot 3.2.3 ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By netimu

I am working on a project involving earth map projections.
I am trying to compute the gradient vector of a certain Scalar function in the most resource saving way. Does Godot offer a way to do so? if not any sort of help would be much appreciated.

Thank you in advance!!

:bust_in_silhouette: Reply From: Andrea

it depends how you want to approach the issue.
the easier way is probably using dictionaries

var gradient={} #declare empty dictionary
gradient[position_vector]=local_gradient_vector #assign values at each position

although i dont know how “resource saving” this is.

Maybe a very long PoolVector array will compute faster, but it is more difficult to manage as you have to find a smart way to univocally links elements in the array to their position in space (eg: element n. 1000 equal to space position vector (103,2,19)) and viceversa.