We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When creating physics models, I often find myself converting a distance vector (between two points) into a unit vector AND the magnitude. This bugs me simply because I know the computation of the unit vector required the magnitude as well.
One possible design would be give mag() an optional p5.Vector argument, which if provided, fills in the vector with the unit vector:
var v = createVector(20, 10);
var u = createVector();
var m = v.mag(u);
// m has value 22.360679774997898
// u has components [0.8944271909999159, 0.4472135954999579]
Would this be useful to the community at large?
Answers
AFAIK, only these 3 methods invokes mag() or magSq():
Dunno exactly what you're asking above. But iMO, if performance is the aim, those 3 methods could accept an optional magnitude value in order to avoid the extra calculation. *-:)
You can request such features, and try your luck out, directly on p5.js's repo: :D
https://GitHub.com/processing/p5.js/issues