Made for this reddit post: https://www.reddit.com/r/Sabermetrics/comments/itmts8/how_are_baseballsavant_visualizations_made/
Most of this was auto generated by: https://threejs.org/editor/
The only actual coding I did was writing a small script to spin the ball (which is now located in app.json -> scripts
):
// Pitch's rotation in radians per second
var spinRate = new THREE.Euler( 0.8, 0, -1.2, 'XYZ' );
function update( e ) {
var deltaSeconds = e.delta / 1000;
this.rotateX( spinRate.x * deltaSeconds )
this.rotateY( spinRate.y * deltaSeconds )
this.rotateZ( spinRate.z * deltaSeconds )
}
Alternatively if you only had spin axis and spin rate you could do something like this (untested and unimplemented):
// Pitch's axis of rotation (should probably be normalized)
var spinAxis = new THREE.Vector3( -0.4, 0, 0.6 );
// Pitch's rotational speed in radians per second
var spinRate = 2;
function update( e ) {
var deltaSeconds = e.delta / 1000;
this.rotateOnAxis( spinAxis, spinRate * deltaSeconds )
}
- You can run this project as a web server and the index page will be a working animation.
- You can also import the app.json file into the threejs editor, I would reccomend this if you wanted to change the lighting / texture or anything like that
- If you don't like js and/or are transfering this to another language, take the above as psuedocode and create/find your own implementation. Here is a helpful explanation of rotating around an axis.