javascript - How can I project a cube onto an axis in a quick manner? -
i going projection of cube onto axis. basically, doing dot product of every vertex of cube axis , compare results find out smallest , greatest values. @ end of day, these 2 values tell me point of axis projected starts , ends. have written following function that; however, thing there lot of comparisons in , because going call function thousands of time whole code runs slow. looking optimization make code faster. function has lot of comparisons , wondering if there way can minimize amount of comparisons in it. ideas? the code written in javascript considering doing on c++ , opengl open suggestions on different programming languages. function projectcube (axis, cube) { pro = dotprodcut(axis, cube.vertex0); minpro = pro; maxpro = pro; pro = dotprodcut(axis, cube.vertex1); if (pro < minpro) { minpro = pro; } if (pro > maxpro) { maxpro = pro; } pro = dotprodcut(axis, cube.vertex2); if (pro < minpro) { minpro = pro; } if (pro > maxp...