Carney转发了
The power of sine and cosine in animation: If you're doing any kind of programmatic animation, sine and cosine are two of the most useful tools to have up your sleeve. 🔄 Cyclical Motion with Easing As shown in the attached chart, given any angle these functions will always return a value between 1 and -1. Incrementing the input angle (θ) and multiplying by some maximum distance from a center point allows you to move an object back and forth with a built in ease in and ease out to the motion. But think beyond simple X and Y movement. You can also constrain an angle of rotation. Picture an animated mechanical arm pivoting on a joint. But rather than a full 360° range of motion you want to constrain the motion to ±45°. You can do that with an equation like this: rotation = 45 * cos(θ) This uses θ to cycle from 0° to 360° as an input, but creates an output that is always between -45° and 45°. 🌐 Polar to Rectangular Transformations Polar coordinates based on a radius (r) and an angle (θ) are great for plotting circular paths and more exotic curved shapes as well. But translating that movement to useable X and Y coordinates requires sine and cosine as follows: x = r cos θ y = r sin θ ⚠️ Mind Your Degrees and Radians For any of this to work, carefully check the documentation of your scripting language. The input for θ may need to be in radians (0 to 2π as in the attached graph) rather than degrees (0° to 360°). On the other hand the output for the rotation of an object may need to be in degrees. 🙃 Unless you are great at thinking in radians you probably want to keep track of your θ values as degrees and then convert to radians. Create a conversion variable once and re-use it as often as needed. For example: DEG_RAD = π/180 x = r * cos(θ * DEG_RAD) y = r * sin(θ * DEG_RAD) All this is just a starting point. Once you grasp the power of sine and cosine as animation tools, you can create even more complex, fluid, and organic scripted animations. #animation #math [Image credit: https://lnkd.in/eqQFYkCf]