Monday, September 16, 2019

How to calculate areas of triangles and polygons

3 vertices and cross product

If 3 vertices' coordinates are given, the size of the cross product of the two vectors is same to two times of the triangle area.
삼각형의 3꼭지점 좌표를 알고 있다면, 인접한 두 벡터의 외적의 크기는 삼각형 면적의 두배와 같다.

$$ A = 0.5|(p_2-p_1)\times(p_3-p_1)| \tag{1}$$

If $\vec{N}$ is the result of the cross product of the two vectors, $\vec{p_1p_2}$ and $\vec{p_1p_3}$, the size of $\vec{N}$ is same to the parallelogram including $\vec{p_1p_2}$ and $\vec{p_1p_3}$.
만약 $\vec{N}$이 두 벡터 $\vec{p_1p_2}$ and $\vec{p_1p_3}$의 외적이면, $\vec{N}$의 크기는 두 벡터 두 벡터 $\vec{p_1p_2}$ and $\vec{p_1p_3}$을 포함하는 평행사변형의 면적과 같다.

Using the cross product and vertices' coordinates, we can get the area of a polygon by spliting a polygon into sub-triangles.
벡터외적과 꼭지점들의 좌표를 이용하면, 다각형을 내부의 작은 삼각형으로 분할하여 그 면적을 계산할 수 있다.

$$ A = \sum_{i=2}^{n-1} 0.5|(p_i-p_1)\times(p_{i+1}-p_1)| \tag{2}$$

We should know the limitation that any vector defiend by two vertices cannot intersect with any side of the polygon.
두 개의 꼭지점으로 정의되는 어떤 벡터도 다각형의 어떤 변과도 만나면 안된다는 한계점을 알고 있어야 한다.

This page will be update for how to calculate a complex polygon's area.

Sunday, September 15, 2019

Photogrammetric Intersection

Linear Intersection for a Stereo Pair

There are two images.
Object point vs. image point, in the first image:
$$ \begin{pmatrix} X \\ Y \\ Z \end{pmatrix} = \begin{pmatrix} X^0_a \\ Y^0_a \\ Z^0_a \end{pmatrix} + {\lambda_a}{R_a} \begin{pmatrix} x_a \\ y_a \\ -f_a \end{pmatrix} \tag{1} $$
Object point vs. image point, in the second image:
$$ \begin{pmatrix} X \\ Y \\ Z \end{pmatrix} = \begin{pmatrix} X^0_b \\ Y^0_b \\ Z^0_b \end{pmatrix} + {\lambda_b}{R_b} \begin{pmatrix} x_b \\ y_b \\ -f_b \end{pmatrix} \tag{2} $$
Therefore,
$$ \begin{pmatrix} X^0_b \\ Y^0_b \\ Z^0_b \end{pmatrix} - \begin{pmatrix} X^0_a \\ Y^0_a \\ Z^0_a \end{pmatrix} = {\lambda_a}{R_a} \begin{pmatrix} x_a \\ y_a \\ -f_a \end{pmatrix} - {\lambda_b}{R_b} \begin{pmatrix} x_b \\ y_b \\ -f_b \end{pmatrix} \tag{3} $$ $$ \begin{pmatrix} r_{11_a}x_a + r_{12_a}y_a - r_{13_a}f_a & - r_{11_b}x_b - r_{12_b}y_b + r_{13_b}f_b \\ r_{21_a}x_a + r_{22_a}y_a - r_{23_a}f_a & - r_{21_b}x_b - r_{22_b}y_b + r_{23_b}f_b \\ r_{31_a}x_a + r_{32_a}y_a - r_{33_a}f_a & - r_{31_b}x_b - r_{32_b}y_b + r_{33_b}f_b \end{pmatrix} = \begin{pmatrix} X^0_b - X^0_a \\ Y^0_b - Y^0_a \\ Z^0_b - Z^0_a \end{pmatrix} \tag{4} $$
where, $ \begin{pmatrix} X \ Y \ Z \end{pmatrix}^T $ are object coordinates,
$\begin{pmatrix} X^0_a \ Y^0_a \ Z^0_a \end{pmatrix}^T$, $\begin{pmatrix} X^0_b \ Y^0_b \ Z^0_b \end{pmatrix}^T$, $R_a$, and $R_b$ denote positoions and attitudes of two images. $\begin{pmatrix} x_a \ y_a \ -f_a \end{pmatrix}^T$ and $\begin{pmatrix} x_b \ y_b \ -f_b \end{pmatrix}^T$ are photo coordinates of each image. If two images are obtained by a camera, $f_a = f_b$.
In the equation (4), there are two unknowns ($\lambda_a$ and $\lambda_b$) and three linear equations. Once $\lambda_a$ and $\lambda_b$ are determined, we get two sets of object coordinates from two scale factors and can use mean values of them.

General Case: Linear Intersection for Multiple Images

$$ \left. \begin {matrix} \begin{pmatrix} X \\ Y \\ Z \end{pmatrix} - {\lambda_1}{R_1} \begin{pmatrix} x_1 \\ y_1 \\ -f_1 \end{pmatrix} = \begin{pmatrix} X^0_1 \\ Y^0_1 \\ Z^0_1 \end{pmatrix} \\ \begin{pmatrix} X \\ Y \\ Z \end{pmatrix} - {\lambda_2}{R_2} \begin{pmatrix} x_2 \\ y_2 \\ -f_2 \end{pmatrix} = \begin{pmatrix} X^0_2 \\ Y^0_2 \\ Z^0_2 \end{pmatrix} \\ \vdots \\ \begin{pmatrix} X \\ Y \\ Z \end{pmatrix} - {\lambda_n}{R_n} \begin{pmatrix} x_n \\ y_n \\ -f_n \end{pmatrix} = \begin{pmatrix} X^0_n \\ Y^0_n \\ Z^0_n \end{pmatrix} \end {matrix} \right ] \tag{5} $$
Threrefore,
$$ \begin{pmatrix} 1 & 0 & 0 & -r_{11_1}x_1 - r_{12_1}y_1 + r_{13_1}f_1 & \cdots \\ 0 & 1 & 0 & -r_{21_1}x_1 - r_{22_1}y_1 + r_{23_1}f_1 & \cdots \\ 1 & 0 & 1 & -r_{31_1}x_1 - r_{32_1}y_1 + r_{33_1}f_1 & \cdots \\ 1 & 0 & 0 & 0 & -r_{11_2}x_2 - r_{12_1}y_2 + r_{13_2}f_2 & \cdots \\ 0 & 1 & 0 & 0 & -r_{21_2}x_2 - r_{22_2}y_2 + r_{23_2}f_2 & \cdots \\ 0 & 0 & 1 & 0 & -r_{31_2}x_2 - r_{32_2}y_2 + r_{33_2}f_2 & \cdots \\ \vdots \\ 1 & 0 & 0 & 0 & 0 & \cdots & -r_{11_n}x_n - r_{12_n}y_n + r_{13_n}f_n \\ 0 & 1 & 0 & 0 & 0 & \cdots & -r_{21_n}x_n - r_{22_n}y_n + r_{23_n}f_n \\ 0 & 0 & 1 & 0 & 0 & \cdots & -r_{31_n}x_n - r_{32_n}y_n + r_{33_n}f_n \end{pmatrix} \begin{pmatrix} X \\ Y \\ Z \\ \lambda_1 \\ \lambda_2 \\ \vdots \\ \lambda_n \end{pmatrix} = \begin{pmatrix} X^0_1 \\ Y^0_1 \\ Z^0_1 \\ X^0_2 \\ Y^0_2 \\ Z^0_2 \\ \lambda_2 \\ \vdots \\ X^0_n \\ Y^0_n \\ Z^0_n \end{pmatrix} \tag{6} $$
In the equation (6), there are $(3+n)$ unknowns ($\begin{pmatrix}X&Y&Z\end{pmatrix}^T$, and $3n$ equations. If there are 2 or more than 2 images, there should be redundancy.