Smilebags / p5.dimensions.js

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

Used object literals #21

Closed max0410 closed 7 years ago

Smilebags commented 7 years ago

Thanks for the merge. It saves a bit of time so it will ultimately allow this to work better.

max0410 commented 7 years ago

Do you have any more plans for this repo? If so, please make a TODO list.

Smilebags commented 7 years ago

I can't think of anything at the moment, but I will be using it on occasions and will likely come across things which would be useful to add. If you have any features you would like to add, or ideas for the direction of this repo, feel free to let me know.

I think it would be cool to work on some 4d object viewer. This library should make it quite a lot easier. Is that something that interests you? Do you have any plans for things to do with it?

max0410 commented 7 years ago

I briefly thought about making a nObject class. Where you could create your own n-dimensional object. You would pass it an object: { "nodes":[nVector,nVector,nVector,nVector], "connections":[ "0":"1", //0th index of nodes array "2":"3", "0":"2", "1":"3" ] }

But I only though of two methods:

This moves the object: nObject.shift(x,y,z,a...)

This sees if two objects are touching: nObject.touching(nObject)

I couldn't think of any use for it yet, or more methods. So I don't know if its worth making. What do you think?

Smilebags commented 7 years ago

I've been thinking long and hard about that sort of thing and how to best implement it. It is something that the computer graphics industry has found difficult enough in just 3 dimensions.

I believe it would be entirely possible to create an nObject class. If we did make it, there would be many uses for it, I believe. But it is by no means a simple task.

Some things which I can think of is the ability to create a 3d 'shadow' or 'slice' object from a 4D object. Although I think an nD to n-1D projection matrix would be doable, that would be a monstrous task, probably best left to people with a doctorate in mathematics..

The issue is with making the object's methods flexible enough that it is easy enough to use. The connections you mention are necessary, but faces also might be needed. Faces, put simply, are a connection between 3 vertices which are each connected to each other as an edge link. You see how it starts getting pretty complex.

Another thing which is unresolved in my mind is a standard for rotation in nD. I think what is needed is to define 2 dimensions, and an angle. This will define the plane of rotation, and then rotate by the amount needed. Can you confirm/explain a better general solution for rotation? In 3D, conveniently, choosing 1 axis to rotate 'around' means you're rotating in the plane created by the other two dimensions, for example, rotating around the x axis can also be defined as rotating in the ZY plane. The second definition can be generalised to nD but the first can't. Do you see what I'm getting at? Maybe we should try implementing a nD rotation method for vectors to start with?

Sorry for the long message, just explaining the ideas I have in my mind.

Smilebags commented 7 years ago

Your shift method also brings up an interesting point. That shift method could call an underlying nMatrix, which allows for rotation, translation, and scale, as well as shear. Maybe we extend the library towards dealing with vectors with matrices. If you're not really sure what I'm on about, you might find Computerfile's video series on Computer Graphics interesting.

Smilebags commented 7 years ago

I'm working on an initial nObject constructor function, but the power will come with what utility functions we can write for it.

Smilebags commented 7 years ago

Once we have the basic data structure laid out we can start on the fun stuff. I'll try to commit it soon and see if you have any suggestions.