-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathbarycentric.tex
109 lines (91 loc) · 2.92 KB
/
barycentric.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\section{Barycentric Coordinates}
Barycentric coordinates enable you to evenly interpolate between three values among the verticies of a triangle.
\def\xa{0} \def\ya{0}
\def\xb{1} \def\yb{2}
\def\xc{3} \def\yc{-1}
\def\xp{1} \def\yp{0.25}
\begin{center}
\begin{tikzpicture}
\draw[gray, thick] (\xa,\ya) -- (\xb,\yb);
\draw[gray, thick] (\xb,\yb) -- (\xc,\yc);
\draw[gray, thick] (\xc,\yc) -- (\xa,\ya);
\draw[gray, thick, dotted] (\xa,\ya) -- (\xp,\yp);
\draw[gray, thick, dotted] (\xb,\yb) -- (\xp,\yp);
\draw[gray, thick, dotted] (\xc,\yc) -- (\xp,\yp);
\filldraw[black] (\xa,\ya) circle (2pt) node[anchor=west]{$v_1$};
\filldraw[black] (\xb,\yb) circle (2pt) node[anchor=west]{$v_2$};
\filldraw[black] (\xc,\yc) circle (2pt) node[anchor=west]{$v_3$};
\filldraw[black] (\xp,\yp) circle (2pt) node[anchor=west]{$p$};
\end{tikzpicture}
\end{center}
\begin{align}
U &= (u_1, u_2, u_3) \\
v_1 &= (x_1, y_1) \\
v_2 &= (x_2, y_2) \\
v_3 &= (x_3, y_3) \\
p &= (x_p, y_p)
\end{align}
The Barycentric coordinates can be defined in terms of the following relationships:
\begin{align}
\begin{cases}
& u_1 + u_2 + u_3 = 1 \\
& u_1x_1 + u_2x_2 + u_3x_3 = x_p \\
& u_1y_1 + u_2y_2 + u_3y_3 = y_p
\end{cases}
\end{align}
Let's reduce the amount of variables in these equations:
\begin{align}
& u_3 = 1 - u_1 - u_2 \\
& \begin{cases}
u_1(x_1 - x_3) + u_2(x_2 - x_3) &= x_p - x_3 \\
u_1(y_1 - y_3) + u_2(y_2 - y_3) &= y_p - y_3 \\
\end{cases}
\end{align}
Now we can turn the system of equations into matrix form:
\begin{align}
& T =
\begin{bmatrix}
x_1 - x_3 & x_2 - x_3 \\
y_1 - y_3 & y_2 - y_3 \\
\end{bmatrix} \\
& U = \begin{bmatrix}
u1 \\ u2 \\
\end{bmatrix}\\
& R = \begin{bmatrix}
x_p - x_3 \\
y_p - y_3 \\
\end{bmatrix} \\
& T \cdot U = R
\end{align}
So the solution is
\begin{align}
U = T^{-1} \cdot R
\end{align}
The main effort goes towards finding $T^{-1}$
\begin{align}
& T^{-1} = \frac{adj(T)}{det(T)} \\
& det(T) = (x_1 - x_3)(y_2 - y_3) - (x_2 - x_3)(y_1 - y_3) \\
& adj(T) = \begin{bmatrix}
y_2 - y_3 & x_3 - x_2 \\
y_3 - y_1 & x_1 - x_3 \\
\end{bmatrix} \\
& T^{-1} = \frac{1}{det(T)} \cdot \begin{bmatrix}
y_2 - y_3 & x_3 - x_2 \\
y_3 - y_1 & x_1 - x_3 \\
\end{bmatrix} \\
& T^{-1}\cdot R = \frac{1}{det(T)} \cdot \begin{bmatrix}
(y_2 - y_3)(x_p - x_3) + (x_3 - x_2)(y_p - y_3) \\
(y_3 - y_1)(x_p - x_3) + (x_1 - x_3)(y_p - y_3) \\
\end{bmatrix}
\end{align}
And the final formula you need to find $(u_1, u_2, u_3)$ given the points $v_1, v_2, v_3, p$~is
\begin{align}
u_1 &= \frac{(y_2 - y_3)(x_p - x_3) + (x_3 - x_2)(y_p - y_3)}{(x_1 - x_3)(y_2 - y_3) - (x_2 - x_3)(y_1 - y_3)} \\
u_2 &= \frac{(y_3 - y_1)(x_p - x_3) + (x_1 - x_3)(y_p - y_3)}{(x_1 - x_3)(y_2 - y_3) - (x_2 - x_3)(y_1 - y_3)} \\
u_3 &= 1 - u_2 - u_1
\end{align}
\end{document}