MeshLib C++ Docs
Loading...
Searching...
No Matches
MRBezier.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4#include "MRVectorTraits.h"
5#include <array>
6
7namespace MR
8{
11
12
14template <typename V>
16{
18 using T = typename VTraits::BaseType;
19 static constexpr int elements = VTraits::size;
20
22 V p[4];
23
25 V getPoint( T t ) const;
26
28 static std::array<T, 4> getWeights( T t );
29};
30
31template <typename V>
33{
35 V q[3];
36 for ( int i = 0; i < 3; ++i )
37 q[i] = lerp( p[i], p[i+1], t );
38
39 V r[2];
40 for ( int i = 0; i < 2; ++i )
41 r[i] = lerp( q[i], q[i+1], t );
42
43 return lerp( r[0], r[1], t );
44}
45
46template <typename V>
47inline auto CubicBezierCurve<V>::getWeights( T t ) -> std::array<T, 4>
48{
49 T s = 1 - t;
50 std::array<T, 4> w =
51 {
52 s * s * s,
53 3 * s * s * t,
54 3 * s * t * t
55 };
56 w[3] = 1 - w[0] - w[1] - w[2];
57 return w;
58}
59
60}
V p[4]
4 control points
Definition MRBezier.h:22
static std::array< T, 4 > getWeights(T t)
computes weights of every control point for given parameter value, the sum of all weights is equal to...
Definition MRBezier.h:47
static constexpr int size
Definition MRMesh/MRVectorTraits.h:22
typename VTraits::BaseType T
Definition MRBezier.h:18
V getPoint(T t) const
computes point on the curve from parameter value
Definition MRBezier.h:32
static constexpr int elements
Definition MRBezier.h:19
T BaseType
The base template handles scalars (or just non-vectors).
Definition MRMesh/MRVectorTraits.h:21
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Cubic Bezier curve.
Definition MRBezier.h:16
Common traits for (mathematical) vectors.
Definition MRMesh/MRVectorTraits.h:18