cgv
Loading...
Searching...
No Matches
convert_curve.h
1#pragma once
2
3#include <array>
4
5#include "bezier.h"
6#include "hermite.h"
7
8namespace cgv {
9namespace math {
10
17template<typename T>
18static std::array<T, 5> split_hermite_to_quadratic_beziers(const hermite_node<T>& n0, const hermite_node<T>& n1) {
19 std::array<T, 5> bez;
20 bez[0] = n0.val;
21 bez[1] = n0.val + n0.tan * T(0.2667);
22 auto h = n1.val - n1.tan * T(0.2667);
23 bez[2] = (bez[1] + h) * T(0.5);
24 bez[3] = h;
25 bez[4] = n1.val;
26 return bez;
27}
28
29template<typename T>
30static std::array<T, 4> hermite_to_cubic_bezier(const hermite_node<T>& n0, const hermite_node<T>& n1) {
31 return {
32 n0.val,
33 n0.val + n0.tan / T(3),
34 n1.val - n1.tan / T(3),
35 n1.val
36 };
37}
38
39template<typename T>
40static std::pair<hermite_node<T>, hermite_node<T>> cubic_bezier_to_hermite(const T& p0, const T& p1, const T& p2, const T& p3) {
41 T t0 = T(3) * (p1 - p0);
42 T t1 = T(3) * (p3 - p2);
43 return { { p0, t0 }, { p3, t1 } };
44}
45
46} // namespace math
47} // namespace cgv
the cgv namespace
Definition print.h:11