kaifronsdal / Advanced_Animation

0 stars 0 forks source link

Snake code could use some documentation #1

Open lorankary opened 5 years ago

lorankary commented 5 years ago

The Snake project Lab 926 is awesome and deserves to be studied. I can generally understand the code that makes the boid and the snake move but I would like to fully understand it. Unfortunately there is a lack of documentation in the code that would help in that effort. Perhaps the algorithms, such as that which guides the boid, are taken from somewhere that they are documented and all that is necessary is to add some comments to the code that cite and reference the source of that documentation.

kaifronsdal commented 5 years ago

I've updated my code to try to explain each but of code. I also gave links to the relevant nature of code chapter (6.5).

lorankary commented 5 years ago

Kai,

Your code: //find a point on a sphere given by the two angles theta and alpha let spherePoint = new Vector(Math.cos(this.theta) Math.sin(this.alpha), Math.cos(this.alpha) Math.sin(this.theta), Math.cos(this.alpha));

bears a strong resemblance to this from https://en.wikipedia.org/wiki/Sphere#Equations_in_three-dimensional_space The points on the sphere with radius and center can be parameterized via

[4] https://en.wikipedia.org/wiki/Sphere#cite_note-4 except that the value that you have for y is cos(alpha) sin(theta) and wikipedia has sin(alpha) sin(theta).

So that makes me wonder even more where exactly you got your example code and if it is correct. Actually I think I can say that your code is not correct because you would expect spherePoint to always have a magnitude of 1.0 but it doesn’t until you change your code to be sin sin instead of cos sin and then it does always have a magnitude of 1.0 or very close. To observe, just add this line of code -- console.log(spherePoint.mag());

The wikipedia article does not say what alpha and theta are but I believe there is a presumption that they are relative to radii that are orthogonal as shown in the image https://en.wikipedia.org/wiki/Sphere#/media/File:Sphere_and_Ball.png https://en.wikipedia.org/wiki/Sphere#/media/File:Sphere_and_Ball.png

Now I would just like to find something that shows me how those equations for points on a sphere are derived.

On Oct 8, 2018, at 3:28 PM, kaifronsdal notifications@github.com wrote:

I've updated my code to try to explain each but of code. I also gave links to the relevant nature of code chapter (6.5).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kaifronsdal/Advanced_Animation/issues/1#issuecomment-427999305, or mute the thread https://github.com/notifications/unsubscribe-auth/AVn4F7adz9vUXw7OdjpY66JZUunOjwptks5ui9GNgaJpZM4XNp7v.