For use only on NTSC Genesis Systems.
Avatar image by CyanSorcery!


Tumblr (inactive)
tumblokami.tumblr.com/
Twitter (inactive)
twitter.com/Techokami

Thew
@Thew

So like, a Very Long Time Ago I made these cool swirly curves while working on aerobat vfx stuff

Conceptually it's really simple:
Imagine a car driving at a constant speed. As it drives, the steering wheel is turned left/right according to some function. In this case it's just a cosine wave, i.e. you just smoothly wobble the wheel back and forth. By simply changing how fast the steering wheel oscillates, and how far from the center it's allowed to turn, the path of the car plots these different curves.

This is really easy to plot over time in a game, or in a single for-loop. It's a basic Turtle Graphics situation [turtles are operated by steering wheels]

OKAY BUT


What if you don't want a for loop. What if you just want to ask "at time t, where is the car" and just calculate the answer directly.
It's just a cosine function; it SEEMS like someone would have dug into this before. I asked around on twitter but nobody could answer so instead I ended up Doing Math.

tl;dr: haha you can't

You're welcome to stop reading now but I did all that math so I might as well explain it. There is, as Math Dorks like to say, No Closed-Form Solution.

Here's a desmos graph where I figured out the actual math and made a bunch of sliders you can play with

Basically: If you have a function that describes the movement of a steering wheel, the direction of travel at an arbitrary time depends on all previous movements of the wheel. So "What direction is the car moving" is just the definite integral of your steering-wheel function.

Since the speed is constant and we can exactly calculate the direction, we now know the velocity at any point in time, so we can get the position of the car by summing all previous velocities, which is.... ahhh right shit that's another integral

now we're into second-order integrals. we have been hurled into The Math Zone

Well I mean, it's literally just a cosine and some constants. How bad can it be hm well fuck

yeah so apparently integrals involving nested sin/cos functions have "no closed-form solution" which sounds very clever to say but what it actually means is I threw this at a bunch of different computer programs that are supposed to solve integrals and they all broke and then I found a mathoverflow post where people were like "yeah you can't, except a really special case around exactly pi/2" and then I started seeing references to The Method of Frobenius and look man if Stephen "Wolfram" Alpha can't solve your integral I really don't think fucking Doctor Seuss is gonna help here

In Conclusion:

Given that there's no closed form, the remaining option is to estimate the answer using Unicode Math Bold Fraktur Voice Numerical Integration. There's all kinds of crazy elaborate iterative solvers you could throw at this or like sick-ass importance-sampled temporal-reprojected monte-carlo methods but like.
You know what's a really fast highly-accurate algorithm for performing Numerical Integration? A for-loop with a turtle in it.


You must log in to comment.

in reply to @Thew's post:

turtles are so good, i had to do brownian motion for some fx and it was as easy as doing "accumulate angle / e^2", i guess thats why a lot of more advanced calculus is just PDEs (turtles in a trenchcoat) and system dynamics and stuff

OH MY GOD I MIGHT HAVE BEEN STUDYING ALMOST THE EXACT SAME PROBLEM RECENTLY. FM synthesis involves making waves which look like sin(at + sin(bt)). there's also no closed form solution, but apparently it is possible to take the fourier transform somehow because we know the fourier series

nah it's fine

actually since most of my time is spent on GPUs, rather than Euler Integration ("adding, in a loop") I typically prefer Monte Carlo Integration ("guessing several times")

tbh I have the exact opposite take lol

almost EVERYTHING you could ever want to calculate in the real world is probably an integral. It's one of the most fundamental concepts in existence. There are a billion things wrong with math education but ONE of them is the fact that it treats Calculus as Super Advanced Hardcore Math for Nerds when it's actually one of the most intuitive subjects in the whole field

You could (should!) teach 13 year olds about integrals and derivatives. Integrals are literally just addition lol. Math education could be "hey you want to draw cool swirly shapes? want to know how a gyroscope works?" but instead only a subset of nerds over 18 get to learn math that makes sense while meanwhile Literally Everyone is forced to memorize the fucking quadratic formula for no reason

integrals are very much not just addition. the amount of measure theory and analysis you need to make the notion of an integral rigorous is kind of ludicrous, and none of it is intuitive unless you're deep into analysis hell. you can explain the idea behind integration to 13 year olds, but you're not going to be able to make anything you're talking about mathematically sound without giving them an entire math degree's worth of education.

basically the entirety of high school calculus is based on handwavy, non-rigorous notions of limits and measure, and it leads to integration and derivation being treated as magic symbol boxes rather than any real understanding of them, because engineers don't actually need any of the rigor and the US math education system was designed to pump out aerospace engineers in the mid 20th century.

also, integration is in general impossible to calculate. most functions which are integrable don't have closed-form expressions of their integrals, and actually calculating or reasoning about integrals is capital-h Hard