I know that "how to optimize this code?" kind of question is generally not welcomed in stack overflow. But I think this is only the way i could phrase my question. I wrote a code that projects a 4 dimensional points onto a 3 dimensional space. I then draw the 3d points using the p5.js library.
Here is my code: https://jsfiddle.net/dfq8ykLw/
Now my question here is, how am I supposed to make this run faster, and optimize the code? Since I am supposed to draw few thousand points (sometimes more) per frame, and calculate the rotation for each of those points, my code tend to run incredibly slowly (mac devices can run this a little faster for some reason).
I tried drawing points instead of vertices, which ended up running even slower.
Are there any suggestion of how to improve the performance? Or an advice of what kind of library to use for drawing 3 dimensional shapes?
Just to explain, my program stores the points as nested array, just like [[Point object, Point object, ...], ...]
.
Each array in the data works as a face, with each Point
object being the vertices.
I first rotate each of these points by applying 6 rotations (for axis xy, xz, xw, yz, yw and zw), then draw them by projecting them onto the 3d space.
Any help is appreciated, as I am terribly stuck!