Geometry Processing: Curvature

An example from Geometry Processing: Curvature

The original equation:

placeholder

I❤️LA implementation:

`H(p)` = 1/(2π)∫_[0, 2π] `kₙ`(φ, p) ∂φ

where 

p ∈ ℝ^3 : point on the surface
`kₙ`: ℝ,ℝ^3 → ℝ : normal curvature

I❤️LA compiled to Python/NumPy/SciPy:

"""
`H(p)` = 1/(2π)∫_[0, 2π] `kₙ`(φ, p) ∂φ

where 

p ∈ ℝ^3 : point on the surface
`kₙ`: ℝ,ℝ^3 → ℝ : normal curvature
"""
import numpy as np
import scipy
import scipy.linalg
from scipy import sparse
from scipy.integrate import quad
from scipy.optimize import minimize


class course_curvatureResultType:
    def __init__( self, H_left_parenthesis_p_right_parenthesis):
        self.H_left_parenthesis_p_right_parenthesis = H_left_parenthesis_p_right_parenthesis


def course_curvature(p, kₙ):
    """
    :param :p : point on the surface
    :param :kₙ : ℝ,ℝ^3 → ℝ : normal curvature
    """
    p = np.asarray(p, dtype=np.float64)

    assert p.shape == (3,)

    H_left_parenthesis_p_right_parenthesis = 1 / (2 * np.pi) * quad(lambda φ: kₙ(φ, p), 0, 2 * np.pi)[0]
    return course_curvatureResultType(H_left_parenthesis_p_right_parenthesis)


def generateRandomData():
    p = np.random.randn(3)
    def kₙ(p0, p1):
        return np.random.randn()
    return p, kₙ


if __name__ == '__main__':
    p, kₙ = generateRandomData()
    print("p:", p)
    print("kₙ:", kₙ)
    func_value = course_curvature(p, kₙ)
    print("return value: ", func_value.H_left_parenthesis_p_right_parenthesis)

I❤️LA compiled to MATLAB:

function output = course_curvature(p, k_n)
% output = course_curvature(p, `kₙ`)
%
%    `H(p)` = 1/(2π)∫_[0, 2π] `kₙ`(φ, p) ∂φ
%    
%    where 
%    
%    p ∈ ℝ^3 : point on the surface
%    `kₙ`: ℝ,ℝ^3 → ℝ : normal curvature
    if nargin==0
        warning('generating random input data');
        [p, k_n] = generateRandomData();
    end
    function [p, k_n] = generateRandomData()
        p = randn(3,1);
        k_n = @k_nFunc;
        rseed = randi(2^32);
        function tmp =  k_nFunc(p0, p1)
            rng(rseed);
            tmp = randn();
        end

    end

    p = reshape(p,[],1);

    assert( numel(p) == 3 );

    H_p = 1 / (2 * pi) * integral(@(phi) k_n(phi, p), 0, 2 * pi,'ArrayValued',true);
    output.H_p = H_p;
end

I❤️LA compiled to LaTeX:

\documentclass[12pt]{article}
\usepackage{mathdots}
\usepackage[bb=boondox]{mathalfa}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{libertine}
\DeclareMathOperator*{\argmax}{arg\,max}
\DeclareMathOperator*{\argmin}{arg\,min}
\usepackage[paperheight=8in,paperwidth=4in,margin=.3in,heightrounded]{geometry}
\let\originalleft\left
\let\originalright\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\originalleft}
\renewcommand{\right}{\aftergroup\egroup\originalright}
\begin{document}

\begin{center}
\resizebox{\textwidth}{!} 
{
\begin{minipage}[c]{\textwidth}
\begin{align*}
\textit{H(p)} & = \frac{1}{2\pi}\int_{0}^{2\pi} \textit{kₙ}\left( \mathit{φ},\mathit{p} \right) d\mathit{φ} \\
\intertext{where} 
\mathit{p} & \in \mathbb{R}^{ 3} \text{ point on the surface} \\
\textit{kₙ} & \in \mathbb{R},\mathbb{R}^{ 3}\rightarrow \mathbb{R} \text{ normal curvature} \\
\\
\end{align*}
\end{minipage}
}
\end{center}

\end{document}

I❤️LA LaTeX output: