less_retarded_wiki/approximation.md
2022-09-03 14:13:46 +02:00

16 lines
2.6 KiB
Markdown

# Approximation
Approximating means calculating something with lesser than best possible precision -- estimating -- purposefully allowing some margin of error in results and using simpler mathematical models than the most accurate ones: this is typically done in order to save resources (CPU cycles, memory etc.) and reduce [complexity](complexity.md) so that our projects stay manageable. Simulating real world on a computer is always an approximation as we cannot capture the infinitely complex and fine nature of the real world with a machine of limited resources, but even withing this we need to consider how much, in what ways and where to simplify.
Using approximations however doesn't have to imply decrease in precision of the final result -- approximations very well serve [optimization](optimization.md). E.g. approximate metrics help in [heuristic](heuristic.md) algorithms such as [A*](a_star.md). Another use of approximations in optimization is as a quick preliminary check for the expensive precise algorithms: e.g. using bounding spheres helps speed up collision detection (if bounding spheres of two objects don't collide, we know they can't possibly collide and don't have to expensively check this).
Example of approximations:
- **Distances**: instead of expensive **Euclidean** distance (`sqrt(dx^2 + dy^2)`) we may use **Chebyshev** distance (`dx + dy`) or **Taxicab** distance (`max(dx,dy)`).
- **Engineering approximations** ("guesstimations"): e.g. **sin(x) = x** for "small" values of *x* or **pi = 3** (integer instead of float).
- **Physics engines**: complex triangle meshes are approximated with simple analytical shapes such as **spheres**, **cuboids** and **capsules** or at least **convex hulls** which are much easier and faster to deal with. They also approximate **relativistic** physics with **Newtonian**.
- **Real time graphics engines**, on the other hand, normally approximate all shapes with triangle meshes.
- **[Ray tracing](ray_tracing.md)** neglects indirect lighting. Computer graphics in general is about approximating the solution of the rendering equation.
- **Real numbers** are practically always approximated with [floating point](floating_point.md) or [fixed point](fixed_point.md) (rational numbers).
- **[Numerical methods](numerical.md)** offer generality and typically yield approximate solutions while their precision vs speed can be adjusted via parameters such as number of iterations.
- **[Taylor series](taylor_series.md)** approximates given mathematical function and can be used to e.g. estimate solutions of [differential equations](differential_equation.md).