Smilebags / p5.dimensions.js

An addon for p5.js which adds support for higher dimensional calculations.
72 stars 24 forks source link

Feature Parity with p5.Vector.js #8

Closed Smilebags closed 7 years ago

Smilebags commented 7 years ago

I think it would be good if all possible standard vector functions in p5.Vector.js were also implemented here in the same manner. Currently I'm adding 'n' to the start of the functions but this convention could change.

The ones I can see which are missing from p5.Dimensions are:

These might be not as useful/not easy to implement. fromAngle heading rotate angleBetween

max0410 commented 7 years ago

I am trying to implement n dimensional lerp function, but it is really quite hard when the equation for it is this:

image

Smilebags commented 7 years ago

That does indeed look quite complicated. I'll have a closer look at the p5.Vector lerp and see if there is an easier way to implement it. I have a feeling simply adding a certain percentage of the new vector to the existing one might work, but maybe that's not mathematically correct;

v1 = new nVector(1,1,1,1); v2 = new nVector(1,2,3,4);

v1.nLerp(v2, 0.5); // should set v1 to 1, 1.5, 2, 2.5 I think. Maybe my understanding of the function is incorrect.

max0410 commented 7 years ago

For your understanding, lerp or Linear interpolation, is the midpoint between two vectors. Example: image

Smilebags commented 7 years ago

Not necessarily the midpoint, but just some position along the line between the two points. for example:

v1 = new nVector(1,1,1,1); v2 = new nVector(1,2,3,4); v1.nLerp(v2, 0.1); // should set v1 to 1, 1.1, 1.2, 1.3

Smilebags commented 7 years ago

I've committed an initial implementation of nLerp. I'll do some testing to see if it behaves correctly.

max0410 commented 7 years ago

You can remove normalize and setMag off the list.

Smilebags commented 7 years ago

Yes, most of these are complete now.

Smilebags commented 7 years ago

We have completed all the initial functions from p5.Vector. Great work! Next I think we should work on adding this.nAdd(v2) functionality, which should behave the same as nAdd(v1,v2) I have tried adding that functionality to a few functions but I don't believe it is working.