Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation matrix may be computed just once #7

Open
ednl opened this issue Nov 16, 2022 · 2 comments
Open

Rotation matrix may be computed just once #7

ednl opened this issue Nov 16, 2022 · 2 comments

Comments

@ednl
Copy link

ednl commented Nov 16, 2022

This might speed up the simulation, but probably not enough to have an acceptable frame rate in real time. So I guess you would still need to make a time lapse. In that regard, I'm not sure this is worth the trouble.

What the code does now is increment the rotation angle every loop by 1 degree, construct a new rotation matrix and use that matrix only once. Alternatively, you could construct a rotation matrix just once, before the draw loop, with an angle of 1 degree. Then use that matrix every time to transform the current coordinates. This will have the same effect, cumulatively. So instead of using sin and cos every loop and do the matrix multiplication, you have only the multiplication left.

One slight complication is that matrix multiplication p' = R.p can't be done in-place, because the old values would be overwritten when you still need them. So in BASIC, this probably requires juggling with array indices where you transform p(0..7) into p(8..15) on one loop, and p(8..15) into p(0..7) on the next loop.

I hope this is clear and that it will be helpful. Cheers!

@ednl
Copy link
Author

ednl commented Nov 16, 2022

I made an example in P5js. In the sketch code, I cheated by making the points p and rotation matrix R multilevel arrays, which BASIC doesn't have, I think? So that would require some index juggling.

@shiffman
Copy link
Member

Thanks so much for this, glad to be able to discuss during yesterday's live stream! If you would like to submit a pull request with an additional "optimized" cube.bas file that works for me! Or even a README.md file with an explanation! Or this issue can remain as a nice reference!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants