๊ฒ์ ์์ง์์ ๋ฌผ์ฒด๋ ์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฒด๋ก ํํ๋ฉ๋๋ค. ๊ฐ์ฒด(rigid body)๋ ๋ฌผ์ฒด์ ํ์ ๊ฐํด๋ ํ์์ด ๋ณํ์ง ์๋ ๋ฌผ์ฒด๋ฅผ ๋งํฉ๋๋ค. ์ผ๋ฐ์ ์ผ๋ก ๋ฌผ์ฒด๋ ์คํ๋ง๊ณผ ๊ฐ์์ ํ์ ๊ฐํ๋ฉด ์์ถ๋์๋ค๊ฐ ํ์ด ์ฌ๋ผ์ง๋ฉด ์๋๋๋ก ๋์์ค๊ฑฐ๋ ์.
an object are normally treated as a rigid body in game engine for physical calculations. if an object is a rigid body, it means that the object can not deformed by forces acting on the object. In real world the most objects are kinds of spring. they are compressed when a force is acting on them, then it recover its original form when the force is released.
๊ทธ๋ฐ๋ฐ ์ผ๊ตฌ๊ณต์ ๋์ง๋ ์ผ๊ตฌ๊ณต์ ์์ฉํ๋ ํ์ ์ํ ๋ณํ์ด ๊ฑฐ์ ์์ผ๋ ์ด๊ฑธ ๊ณ์ฐํด๋ด์ผ ๊ทธ ๋ณํ๋ ๋จ๋ฉด์ ๋ํ ๊ณต๊ธฐ์ ํญ์ ๋ณํ์ ํฌ๊ธฐ๋ ๊ณ ๋ คํ ๊ฐ์น๋ ์์ด ์๊ฒ ์ง์. ๊ทธ๋์ ๊ฐ์ฒด๋ก ๊ฐ์ ํ๊ณ ๊ณ์ฐํด๋ ๋ฌด๋ฆฌ๊ฐ ์์ต๋๋ค.
let assume a ball is in play and a programmer want simulate the effect of changing drag force from the deformation. the deformation is so small so the change in the drag force is negligible. that's why one can safely consider the ball as rigid body.
๋ฌผ๋ฆฌ ์์ง์ ์๋๋ฅผ ๊ณ์ฐํ ๋, ๋ฌผ์ฒด์ ์์ฉํ๋ ํ์ผ๋ก๋ถํฐ ๊ณ์ฐ ํฉ๋๋ค. ๋ฌผ์ฒด์ ์์ฉํ ํ์์ ๊ฐ์๋๋ฅผ ๊ณ์ฐ ํ ์ ์์ผ๋๊น์. (F = m*a)
๊ฐ์๋ a = F/m ์ธ๊ฑธ ์์์ผ๋ ์๋๋ v = v0 + a*t ๋ผ๋ ๊ณต์์ผ๋ก ๊ณ์ฐํ๋๊ฑด ๋๋ฌด ๋น์ฐํ๊ฒ ์ฃ . ํ์ง๋ง ์ ์์ a๊ฐ ์ผ์ ํ ๊ฒฝ์ฐ์๋ง ์ธ ์ ์์ต๋๋ค. a๊ฐ ์๊ฐ์ ๋ฐ๋ผ ๋ณํ๋ค๋ฉด ๋น์ฐํ ์ธ ์ ์์ต๋๋ค.
the most physical engines calculate velocities from the total external forces of an object. because of F=ma. the formula v = v0 + a*t is trivial. but the limitation is that a is constant in time if not? of cause you can't use it.
ํ์ง๋ง ์ด์งํผ ํ๋ก๊ทธ๋๋จธ๋ค์ ๋งค ํ๋ ์๋ง๋ค ๊ฐ์๋๋ฅผ ๊ณ์ฐํ๋๊น ์ฌ์ค ๋ณ ๋ฌธ์ ๋ ์์ต๋๋ค.
์ฝ๋๋ก ์ด๋ค๋ฉด ์ด๋ ๊ฒ ํ๊ฒ ์ฃ ?
but programmers usually calculate the acceleration at every single frame. the limitation isn't the case. In python code, the velocity is calculated as following:
for i in range(TIME):
a = F[i]/m
v_new = v[i] + a*dt
v.append(v_new)
๊ทธ๋ฐ๋ฐ, ์ ์์ด ์๋ ์ด๋ค ๋ชจ์์ด์๋์ง๊ฐ ๋ ์ฌ๋ฐ๋ ๋ถ๋ถ ์
๋๋ค.
the fun part is the original form of the code.
๋ค์ F=ma ๋ก ๋์๊ฐ์, F = ma๋ F = m*dv/dt ๋ผ๋ ๋ฏธ๋ถ์ด ํฌํจ๋ ์์ผ๋ก ํฌํจ๋ฉ๋๋ค.
dv/dt ๋ v๋ฅผ ์๊ฐ t์ ๋ํด ๋ฏธ๋ถํ ๊ฒ์ด๋ ๊ฐ์๋๋ ํด๋น ์๊ฐ์ ๊ฐ์๋์ด์ง ํ๋ก๊ทธ๋๋จธ๋ค์ด ๊ณ์ฐํ ๋ ์ฐ๋ ํ ํ๋ ์ ์๊ฐ๋์์ ํ๊ท ๊ฐ์๋๋ฅผ ์๋ฏธํ๋๊ฑด ๋น์ฐํ ์๋๊ฒ ์ฃ .
Back to F=ma, F=ma is equal to F = m*dv/dt which has a derivative. dv/dt is an acceleration of a certain time, not the average acceleration along the period like a frame.
๊ฐ์๋๋ฅผ dt ์๊ฐ ๋์์ ๊ธฐ์ธ๊ธฐ๋ก ๋ํ๋ด๋ ์ํ์ ์ธ ๋ฐฉ๋ฒ์ด ์์ฃ . ๋ฐ๋ก ํ
์ผ๋ฌ ๊ธ์.
Taylor series can transform the acceleration to the average acceleration for dt.
f(x) = f(a) + f'(a)(x-a) + f''(a)(x-a)^2/2 + ...
์๋ v๋ฅผ ํ
์ผ๋ฌ ๊ธ์๋ก ๋ํ๋ธ๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
v as a tylor series is represented as following,
v(t) = v(a) + v'(a)(x-a) + v''(a)(x-a)^2 /2 + ...
์์ ํํ์ ๋น๋ฆฌ๋ฉด, ๊ฐ์๋ a = v' ๋๊น ์ด๋ ๊ฒ ํํ๋ฉ๋๋ค:
so, the acceleration a = v' and v' is following
v'(a) = {v(t)-v(a)}/(x-a) - v''(a)*(x-a) /2 - ...
๋ค์ -v''(a)*(x-a)/2 - ... ์ด ๋ถ๋ถ์ ๊ทธ๋ฅ ์ค์ฐจ๋ผ๊ณ ํ๊ณ O(dt) ์ด๋ ๊ฒ ํํํฉ๋๋ค.
the part -v''(a)*(x-a)/2 -... is called as error, which is O(dt)
๊ทธ๋ฌ๋๊น ํ์ฌ ์๊ฐ i ์ผ ๋, dt ์๊ฐ ํ์ ์๋๋ ์ด๋ ๊ฒ ๋ฉ๋๋ค.
finally we get the mathematical form of the code.
v(i+dt) = v(i) + dt * v'(i) + O(dt)
์ด๋ฐ ๊ณผ์ ์ ์ด์ฐํdiscretization ์ด๋ผ๊ณ ํ๊ณ ์ปดํจํฐ๋ก ํ๊ธฐ ์ด๋ ค์ด ๋ฏธ๋ถ ๋ฐฉ์ ์์ ํ๋ก๊ทธ๋๋ฐํ๊ธฐ ์ฌ์ด ๋คํญ์์ผ๋ก ๋ฐ๊พผ ๊ณผ์ ์ ๋๋ค. ํ๋ก๊ทธ๋๋จธ๋ค์ ์ด๋ฐ ๊ณผ์ ์ ์์ฐ์ค๋ฝ๊ฒ ํ๊ณ ์์ต๋๋ค.
์ฐธ๊ณ ๋ก ๊ฐ๋๊ฐ 0๋์ ๊ฐ๊น์ธ ๋, sin(x) ํจ์๋ฅผ x๋ก, cos(x) = 1 ์ด๋ผ๊ณ ๊ฐ์ ํ๋ ์ด์ ๋ ๋ฐ๋ก ํ ์ผ๋ฌ ๊ธ์์ ์ํ ๊ฒ ์ ๋๋ค. sin(x)์ ํ ์ผ๋ฌ ์๋ฆฌ์ฆ๋ฅผ ๊ตฌํ๊ณ , a์ 0์ ๋ฃ์ด๋ณด๋ฉด ํ์ธ ํ ์ ์์ต๋๋ค(์ด ๊ธ์๋ฅผ ๋งฅ๋๋ฆฐ ๊ธ์๋ผ๊ณ ๋ ํฉ๋๋น)
this process changing a derivative to a polynomial is discretization. many difficult differential equations are solved by the numerical method. this is the way programmers doing unconsciously.
plus, when an angle is very close to 0, sin(x) and cos(x) are assumed as x and 1. it's also because of Taylor series. you can see it from Taylor series of sin(x) and cos(x) plugging a =0 (Taylor series with a = 0 is called as Maclaurin series)
๊ทธ๋ฅ ํ์์ ๋ณ ์๊ฐ ์์ด ์๋ ๊ณ์ฐํ๊ณ ์๋ค๊ฐ ์ ์ ๊ฒ ํ ์ผ๋ฌ ๊ธ์์์ง ... ๋ผ๋ ์๊ฐ์ด ๋ค์ด์ ์ ๋ฆฌํ์ต๋๋ค. ์ด์ฐํ๋ฅผ ์ํ๋ ์ฌ๋๋ค์ ๋ฏธ๋ถ ๋ฐฉ์ ์์์ ์ฝ๊ฒ ์์นํด์๊น์ง ์ด๋์ด๊ฐ์๋๋ผ๊ตฌ์.
I used to calculate the velocities and popped it was a Taylor series. people who are good at discretization can easily build a simulations from differential equations.