summaryrefslogtreecommitdiff
path: root/site/content
diff options
context:
space:
mode:
Diffstat (limited to 'site/content')
-rw-r--r--site/content/math/angle_between_two_vectors.typ104
-rw-r--r--site/content/math/atan2.typ107
-rw-r--r--site/content/math/integrating_cos2x.typ (renamed from site/content/integrating_cos2x.typ)2
-rw-r--r--site/content/math/integrating_sin2x.typ (renamed from site/content/integrating_sin2x.typ)2
-rw-r--r--site/content/math/ray_vs_sphere.typ89
-rw-r--r--site/content/math/rotational_symmetries_bravais_lattice.typ80
6 files changed, 382 insertions, 2 deletions
diff --git a/site/content/math/angle_between_two_vectors.typ b/site/content/math/angle_between_two_vectors.typ
new file mode 100644
index 0000000..b779a5f
--- /dev/null
+++ b/site/content/math/angle_between_two_vectors.typ
@@ -0,0 +1,104 @@
+#import "/common.typ": post, link-self, static, img
+
+#show: post.with(
+ title: "Angle between two vectors",
+ date: datetime(year: 2020, month: 4, day: 17),
+)
+
+#figure(
+ img(static("math/angle_between_vectors.png")),
+ caption: [Which one to choose?],
+)
+
+In $RR^n$ there are two angles between any two vectors. The smallest one I'll call $theta$. The other one, its 360° complement, I'll call $phi$.
+
+The smallest angle between two vectors $bold(u)$ and $bold(v)$ is given by:
+
+$
+ theta = cos^(-1)((bold(u) dot bold(v)) / (u v))
+$
+
+which follows easily from the geometric definition of the dot product:
+
+$
+ bold(u) dot bold(v) = u v cos theta
+$
+
+The other angle is simply the 360° complement:
+
+$
+ phi = 2 pi - theta
+$
+
+= Oriented angle
+
+#figure(
+ img(static("math/oriented_angles_between_vectors.png")),
+ caption: [Oriented angles between example vectors *u* and *v*.],
+)
+
+Some applications call for the *oriented* angle $psi$. It's the angle going from one vector to the other in a specific direction. The convention that I use is that the direction be *counter-clockwise*.
+
+Because the angle is oriented, changing the order of vectors (or the used convention) changes the angle's sign:
+
+$
+ psi(bold(u), bold(v)) = -psi(bold(v), bold(u))
+$
+
+or, equivalently:
+
+$
+ psi(bold(u), bold(v)) = 2 pi - psi(bold(v), bold(u))
+$
+
+Furthermore:
+
+$
+ psi(bold(u), bold(u)) = 0
+$
+
+It's also worth noting that:
+
+$
+ cos theta = cos phi = cos psi
+$
+
+which is why the dot product doesn't carry enough information to compute $psi$.
+
+== In two dimensions
+
+In any coordinate system:
+
+$
+ psi(bold(u), bold(v)) &= op("atan2")(bold(u) times_2 bold(v), bold(u) dot bold(v)) \
+ &= op("atan2")(u_1 v^2 - u_2 v^1, u_1 v^1 + u_2 v^2)
+$
+
+== Derivation: in two dimensions
+
+Using the geometric definitions of the #link-self("math/2d_cross_product")[two-dimensional cross product] and the dot product:
+
+$
+ cases(
+ bold(u) dot bold(v) = u v cos theta,
+ bold(u) times_2 bold(v) = u v sin theta,
+ )
+$
+
+Solving for the sine and cosine:
+
+$
+ cases(
+ cos theta = 1 / (u v) bold(u) dot bold(v),
+ sin theta = 1 / (u v) bold(u) times_2 bold(v),
+ )
+$
+
+Solving for $theta$ (see #link-self("math/atan2")[Systems of equations involving the cosine and the sine of an unknown]):
+
+$
+ theta &= op("atan2")(1 / (u v) bold(u) times_2 bold(v), 1 / (u v) bold(u) dot bold(v)) \
+ &= op("atan2")(bold(u) times_2 bold(v), bold(u) dot bold(v))
+$
+
+The simplification can be done because $1 / (u v) > 0$ and eliminating it will not change the result (see #link-self("math/atan2")[properties of atan2]).
diff --git a/site/content/math/atan2.typ b/site/content/math/atan2.typ
new file mode 100644
index 0000000..4e78e56
--- /dev/null
+++ b/site/content/math/atan2.typ
@@ -0,0 +1,107 @@
+#import "/common.typ": post, static, img
+
+#show: post.with(
+ title: "atan2",
+ date: datetime(year: 2018, month: 5, day: 13),
+)
+
+$
+ op("atan2"): RR^2 without (0, 0) -> (-pi, pi]
+$
+
+$
+ op("atan2")(y, x) = cases(
+ +pi / 2, (x = 0) and (y > 0),
+ -pi / 2, (x = 0) and (y < 0),
+ tan^(-1)(y / x), x > 0,
+ tan^(-1)(y / x) + pi, (x < 0) and (y >= 0),
+ tan^(-1)(y / x) - pi, (x < 0) and (y < 0),
+ )
+$
+
+where $tan^(-1) x$ is the principal value of the arctangent, ie. the one in the interval $(-pi, pi]$.
+
+= Properties
+
+#figure(
+ img(static("math/atan2-plot.png")),
+ caption: [A 3D plot of atan2(y, x).],
+)
+
+- $op("atan2")(-y, x) = -op("atan2")(y, x)$
+- $op("atan2")(c y, c x) = op("atan2")(y, x)$ for any $c > 0$.
+- Discontinuous along $(x < 0) and (y = 0)$: For any $x < 0$:
+ - $lim_(y -> 0^-) op("atan2")(y, x) = -pi$
+ - $lim_(y -> 0^+) op("atan2")(y, x) = pi$
+
+== Partial derivatives
+
+The partial derivatives, just like the function itself, are defined everywhere except at the origin. Furthermore, unlike the function, they're not discontinuous along $y = 0$ (except at the origin).
+
+$
+ & (partial)/(partial y) = x / (x^2 + y^2) \
+ & (partial)/(partial x) = -y / (x^2 + y^2)
+$
+
+Interesingly, the function $tan^(-1)(y / x)$ has the same partial derivatives.
+
+= Systems of equations involving the cosine and the sine of an unknown
+
+#figure(
+ img(static("math/polar-coords.png")),
+ caption: [A geometric intepretation: θ = atan2(y,x).],
+)
+
+Let $theta, x, y in RR$. Consider the following system of equations:
+
+$
+ cases(
+ sin theta = y,
+ cos theta = x,
+ )
+$
+
+If $x^2 + y^2 = 1$, this system has a unique (up to a multiple of $2 pi$) solution:
+
+$
+ theta = op("atan2")(y, x) + 2 pi k
+$
+
+for any $k in ZZ$. For simplicity k is often set to zero.
+
+Because $op("atan2")(sin theta, cos theta) = theta$ (up to a multiple of $2 pi$), atan2 can be thought of as the "inverse" of the cosine and sine of the same argument.
+
+= C's atan2
+
+The definition at the beginning of this article is suitable for mathematical analysis. However, a more intricate definition is needed for floating-point computation, one that takes signed zeros and infinites into account. The following appears in the C standard:
+
+$
+ op("atan2")(y, x) = cases(
+ op("NaN") & "if" space (y = op("NaN")) or (x = op("NaN")),
+ plus.minus pi & "if" space (x < +0) and (y = plus.minus 0),
+ plus.minus 0 & "if" space (x > +0) and (y = plus.minus 0),
+ -pi / 2 & "if" space (x = plus.minus 0) and (y < -0),
+ pi / 2 & "if" space (x = plus.minus 0) and (y > +0),
+ plus.minus pi & "if" space (x = -0) and (y = plus.minus 0),
+ plus.minus 0 & "if" space (x = +0) and (y = plus.minus 0),
+ pi & "if" space (x = -infinity) and (y > +0) and (y < +infinity),
+ -pi & "if" space (x = -infinity) and (y < -0) and (y > -infinity),
+ +0 & "if" space (x = +infinity) and (y > +0) and (y < +infinity),
+ -0 & "if" space (x = +infinity) and (y < -0) and (y > -infinity),
+ plus.minus pi / 2 & "if" space (x > -infinity) and (x < +infinity) and (y = plus.minus infinity),
+ plus.minus (3 pi) / 4 & "if" space (x = -infinity) and (y = plus.minus infinity),
+ plus.minus pi / 4 & "if" space (x = +infinity) and (y = plus.minus infinity),
+ tan^(-1)(y / x) & "if" space x > +0,
+ tan^(-1)(y / x) + pi & "if" space (x < -0) and (y >= 0),
+ tan^(-1)(y / x) - pi & "if" space (x < -0) and (y < -0),
+ )
+$
+
+In this definition $op("atan2")(0, 0)$ is *not* undefined.
+
+= See also
+
+- #link("https://linux.die.net/man/3/atan2")[atan2(3)]
+- #link("https://en.wikipedia.org/wiki/Atan2")[Atan2]
+- #link("https://en.wikipedia.org/wiki/Argument_(complex_analysis)")[Argument (complex analysis)]
+- #link("https://en.wikipedia.org/wiki/Inverse_trigonometric_functions")[Inverse trigonometric functions]
diff --git a/site/content/integrating_cos2x.typ b/site/content/math/integrating_cos2x.typ
index a7cfe4b..11fdd67 100644
--- a/site/content/integrating_cos2x.typ
+++ b/site/content/math/integrating_cos2x.typ
@@ -41,7 +41,7 @@ $
= Using the double angle formula
#html.elem("aside", attrs: (class: "warning"))[
- Careful! This derivation differs from the one in #link-self("integrating_sin2x")[integrating_sin2x] by just a sign.
+ Careful! This derivation differs from the one in #link-self("math/integrating_sin2x")[integrating_sin2x] by just a sign.
]
Rewrite the integral using the double angle formula for the cosine:
diff --git a/site/content/integrating_sin2x.typ b/site/content/math/integrating_sin2x.typ
index 65b17a6..ceda615 100644
--- a/site/content/integrating_sin2x.typ
+++ b/site/content/math/integrating_sin2x.typ
@@ -41,7 +41,7 @@ $
= Using the double angle formula
#html.elem("aside", attrs: (class: "warning"))[
- Careful! This derivation differs from the one in #link-self("integrating_cos2x")[integrating_cos2x] by just a sign.
+ Careful! This derivation differs from the one in #link-self("math/integrating_cos2x")[integrating_cos2x] by just a sign.
]
Rewrite the integral using the double angle formula for the cosine:
diff --git a/site/content/math/ray_vs_sphere.typ b/site/content/math/ray_vs_sphere.typ
new file mode 100644
index 0000000..a035596
--- /dev/null
+++ b/site/content/math/ray_vs_sphere.typ
@@ -0,0 +1,89 @@
+#import "/common.typ": post, static, img
+
+#show: post.with(
+ title: "Ray vs. sphere",
+ date: datetime(year: 2018, month: 5, day: 9),
+)
+
+#figure(
+ img(static("math/ray_vs_sphere.png")),
+ caption: [A drawing of a ray intersecting a sphere in two dimensions.],
+)
+
+In $RR^N$, a ray of origin $bold(x)_r$ and direction $bold(v)$ and an N-sphere of origin $bold(x)_s$ and radius $r$ intersect at $bold(x)_I$ given by:
+
+$
+ bold(x)_I = bold(x)_r + t_(plus.minus) bold(v)
+$
+
+where:
+$
+ t_(plus.minus) &= (bold(v) dot bold(u) plus.minus sqrt((bold(v) dot bold(u))^2 - v^2 (u^2 - r^2))) / v^2 \
+ bold(u) &= bold(x)_s - bold(x)_r
+$
+
+If the expression under the square root is negative, there is no intersection. If it's zero, $t_+ = t_-$ and there is only one intersection.
+
+Notice that since $t v$ is the distance to intersection, $t_-$ corresponds to the *closer one* and $t_+$ to the *further*. Depending on the application, you might want to discard negative $t$'s (intersections "behind" the ray).
+
+= Surface normal
+
+The surface normal $hat(bold(n))$ at an intersection is given by:
+
+$
+ bold(r) &= t_(plus.minus) bold(v) - bold(u) \
+ hat(bold(n)) &= hat(bold(r))
+$
+
+= Normalized v
+
+Notice that the expression for $t_(plus.minus)$ becomes appreciably simpler if $v = 1$:
+
+$
+ t_(plus.minus) &= bold(v) dot bold(u) plus.minus sqrt((bold(v) dot bold(u))^2 - (u^2 - r^2))
+$
+
+= Derivation
+
+Notice that the point of intersection lies somewhere on the line defined by the ray:
+
+$
+ bold(x)_I = bold(x)_r + t bold(v)
+$
+
+for some real $t$. It also lies somewhere on the sphere:
+
+$
+ bold(x)_I = bold(x)_s + bold(r)
+$
+
+for some vector $bold(r)$ of length $r$. Combining the two equations and solving for $bold(r)$ yields:
+
+$
+ bold(x)_r + t bold(v) - bold(x)_s = bold(r)
+$
+
+To simplify the algebra, substitute $bold(x)_s - bold(x)_r = bold(u)$:
+
+$
+ t bold(v) - bold(u) = bold(r)
+$
+
+Since only the length of $bold(r)$ is known, the only thing that can be done at this point is equating the norms of both sides. Squared norms are more convenient in this particular case:
+
+$
+ (t bold(v) - bold(u))^2 &= r^2 \
+ t^2 v^2 + u^2 - 2 t bold(v) dot bold(u) &= r^2 \
+ v^2 t^2 - 2 bold(v) dot bold(u) t + u^2 - r^2 &= 0
+$
+
+Solving the quadratic equation and simplifying:
+
+$
+ t_(plus.minus) &= (2 bold(v) dot bold(u) plus.minus sqrt(4 (bold(v) dot bold(u))^2 - 4 v^2 (u^2 - r^2))) / (2 v^2) \
+ t_(plus.minus) &= (bold(v) dot bold(u) plus.minus sqrt((bold(v) dot bold(u))^2 - v^2 (u^2 - r^2))) / v^2
+$
+
+As with any quadratic equation, there is no real solution if the expression under the square root is negative and if it's zero, the solutions coincide.
+
+Notice that $bold(r)$ is perpendicular to the sphere at an intersection. Normalizing this vector yields the surface normal $hat(bold(n))$.
diff --git a/site/content/math/rotational_symmetries_bravais_lattice.typ b/site/content/math/rotational_symmetries_bravais_lattice.typ
new file mode 100644
index 0000000..6ad701d
--- /dev/null
+++ b/site/content/math/rotational_symmetries_bravais_lattice.typ
@@ -0,0 +1,80 @@
+#import "/common.typ": post
+
+#show: post.with(
+ title: "Possible rotational symmetries in a Bravais lattice",
+ date: datetime(year: 2019, month: 4, day: 16),
+)
+
+Any 2- or 3-dimensional Bravais lattice will have *at most* the following rotational symmetries or their compositions:
+
+#table(
+ columns: 3,
+ table.header([*Symmetry*], [*Angle of rotation*], []),
+ [Identity], [$0$], [0°],
+ [2-fold], [$pi$], [180°],
+ [3-fold], [$2 pi / 3$], [120°],
+ [4-fold], [$pi / 2$], [90°],
+ [6-fold], [$pi / 3$], [60°],
+)
+
+Every other rotational symmetry (e.g. 5-fold) is impossible in such a Bravais lattice, regardless of the lattice basis or the chosen rotation axis. This is also known as the #link("https://en.wikipedia.org/wiki/Crystallographic_restriction_theorem")[Crystallographic restriction theorem].
+
+= Proof in three dimensions
+
+Consider a Bravais lattice, a collection of points described as follows:
+
+$
+ bold(x) = n_1 bold(b)_1 + n_2 bold(b)_2 + n_3 bold(b)_3
+$
+
+for $n_1, n_2, n_3 in ZZ$ and some oblique basis ${bold(b)_1, bold(b)_2, bold(b)_3}$. This can be rewritten more compactly as:
+
+$
+ bold(x) = mat(delim: "[", bold(b)_1, bold(b)_2, bold(b)_3) vec(n_1, n_2, n_3) = hat(B) bold(n)
+$
+
+Rotational symmetry means that if the points are rotated around some axis by angle $theta$, they will exactly coincide with the original points. That is, they can be written in the same form as the original points. Representing the multiplication by premultiplication by the rotation matrix $hat(R)_theta$ yields:
+
+$
+ hat(R)_theta bold(x) &= hat(B) bold(n)'
+$
+
+where $bold(n)'$ is some new vector with integer components. Substituting $bold(x) = hat(B) bold(n)$ and premultiplying both sides by $hat(B)^(-1)$:
+
+$
+ hat(R)_theta hat(B) bold(n) &= hat(B) bold(n)' \
+ hat(B)^(-1) hat(R)_theta hat(B) bold(n) &= hat(B)^(-1) hat(B) bold(n)' \
+ &= bold(n)'
+$
+
+The matrix $hat(B)^(-1) hat(R)_theta hat(B)$ transforms one vector with integer components into another. Therefore, it must itself have only integer components and an integer trace. Furthermore, change of basis does not change the trace. Finally, the trace of any rotation matrix in three dimensions equals $1 + 2 cos theta$. Putting this all together yields:
+
+$
+ op("Tr")(hat(B)^(-1) hat(R)_theta hat(B)) = op("Tr")(hat(R)_theta) = 1 + 2 cos theta in ZZ
+$
+
+Rewriting using $k in ZZ$ and knowing that $(forall x in RR)(cos x in [-1, 1])$:
+
+$
+ 1 + 2 cos theta &= k \
+ cos theta &= (1 + k) / 2 \
+ cos theta &in {-1, -1 / 2, 0, 1 / 2, 1}
+$
+
+Ignoring angles outside $[0, 2 pi)$ and solving for $theta$:
+
+$
+ (cos theta = -1) &=> (theta = pi) \
+ (cos theta = -1 / 2) &=> (theta = 2 pi / 3) or (theta = 4 pi / 3) \
+ (cos theta = 0) &=> (theta = pi / 2) or (theta = 3 pi / 2) \
+ (cos theta = 1 / 2) &=> (theta = pi / 3) or (theta = 5 pi / 3) \
+ (cos theta = 1) &=> (theta = 0)
+$
+
+These are the angles from the table in the beginning of the article and their multiplies. For any $theta$ not in this set of solutions, the trace of $hat(B)^(-1) hat(R)_theta hat(B)$ is a non-integer, the matrix itself necessarily has non-integer entries and the $bold(n)'$ vector ends up with non-integer entries. This contradicts the premise, hence the restriction on possible $theta$'s.
+
+= Proof in two dimensions
+
+The proof is almost identical to the case in three dimensions. The only differences are:
+- There's no $n_3$ or $bold(b)_3$ (the appropriate expressions get shorter by a term).
+- The trace of any 2D rotation matrix is $2 cos theta$ (rather than $1 + 2 cos theta$). The results are still the same, though.