requires Affine_Space()
void Affine_Space_test(P p, V u, V v)
{
assert( p + V(0) == p );
assert( (p + u) + v == p + (u + v) );
}
```
---
📚 Example 1: Affine Space in $R^3$
--------------------------------
- A point $a = (a_1, a_2, a_3)$
- A vector $v = [v_1, v_2, v_3]$
- Addition: $a + v = (a_1 + v_1, a_2 + v_2, a_3 + v_3)$
- $a + 0 = a$
- $(a + u) + v = a + (u + v)$
- $b = a + (a \rightarrow b)$
> **Note**: Don’t access the coordinates as possible.
---
📚 Example 2: An Unusual Example
-----------------------------
- A set $P$ consisting of all points $(x, y, z)$ satisfying the
equation $x^2 + y^2 - z = 0$
- Define the action **+** on $P$ such that
- $(x, y, x^2+y^2)$ **+** $[u, v]$ =
$(x + u, y + v, (x + u)^2 + (y + v)^2)$
---
📚 Example 3: C/C++ Pointer Different
----------------------------------
- Probably the most simplest affine space!
- ` = + `
- ` = – `
- Avoid pointer arithmetic
- “Mid-point” of two pointers: `p + (p – q)/2` instead of
`(p + q)/2`
- Similarly, avoid direct coordinate arithmetic as possible! (How?)
---
How to Avoid Coordinate Arithmetic?
-----------------------------------
- Sol’n: Don’t provide arithmetic operators for `` class,
except `operator-()`, which returns a ``
- Advantages:
- Reduce the chance of overflow for integer coordinates (e.g.
mid-point = `p + (p – q)/2` )
- More economic for calculation (e.g. triangle area need 2
multiplications instead of 6)
- Reduce duplicate coding in `` and ``
- Follow concept in mathematics.
---
class: nord-dark, center, middle
# Q&A 🎤