BELFEM
0.9.0
Berkeley Lab Finite Element Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
fn_cubic_bezier.hpp
Go to the documentation of this file.
1
/*
2
* BELFEM -- The Berkeley Lab Finite Element Framework
3
* Copyright (c) 2026, The Regents of the University of California,
4
* through Lawrence Berkeley National Laboratory (subject to receipt of any required
5
* approvals from the U.S. Dept. of Energy). All rights reserved.
6
*
7
* Developers: Christian Messe, Gregory Giard
8
*
9
* See the top-level LICENSE file for the complete license and disclaimer.
10
*/
11
12
#ifndef BELFEM_FN_CUBIC_BEZIER_HPP
13
#define BELFEM_FN_CUBIC_BEZIER_HPP
14
15
#include "
assert.hpp
"
16
#include "
cl_Vector.hpp
"
17
#include "
cl_Matrix.hpp
"
18
19
20
namespace
belfem
21
{
22
//------------------------------------------------------------------------------
23
24
template
<
typename
T >
25
void
26
cubic_bezier
(
27
const
Matrix< T >
& aPoints,
28
Vector< T >
& aWork,
29
const
T & aXi,
30
Vector< T >
& aPoint )
31
{
32
33
BELFEM_ASSERT
( aPoint.
length
() == aPoints.
n_rows
(),
"Length of Point vector does not match"
);
34
BELFEM_ASSERT
( aPoints.
n_cols
() == 4,
"Matrix must have 4 columns"
);
35
BELFEM_ASSERT
( aWork.
length
() == 4,
"Work Vector must have 4 columns"
);
36
37
aWork( 0 ) = std::pow( 1.0 - aXi, 3 );
38
aWork( 1 ) = 3.0 * ( ( aXi *(aXi -1.0)-1.0) * aXi + 1.0 );
39
aWork( 2 ) = 3.0 * ( ( 1.0 - (aXi +1.0)*aXi ) * aXi + 1.0 );
40
aWork( 3 ) =( ( aXi * ( 3.0 + aXi ) + 3.0 ) * aXi + 1.0 );
41
aWork *= 0.125;
42
aPoint = aPoints * aWork;
43
44
// cleanup point
45
for
( T & tX : aPoint )
46
{
47
if
( std::abs( tX ) <
BELFEM_EPSILON
)
48
{
49
tX = 0.0 ;
50
}
51
}
52
}
53
54
//------------------------------------------------------------------------------
55
56
template
<
typename
T >
57
void
58
cubic_bezier_derivative
(
59
const
Matrix< T >
& aPoints,
60
Vector< T >
& aWork,
61
const
T & aXi,
62
Vector< T >
& aPoint )
63
{
64
65
BELFEM_ASSERT
( aPoint.
length
() == aPoints.
n_rows
(),
"Length of Point vector does not match"
);
66
BELFEM_ASSERT
( aPoints.
n_cols
() == 4,
"Matrix must have 4 columns"
);
67
BELFEM_ASSERT
( aWork.
length
() == 4,
"Work Vector must have 4 columns"
);
68
69
70
aWork( 0 ) = - ( 1.0 - aXi) * ( 1.0 - aXi );
71
aWork( 1 ) = ( ( 3.0 * aXi - 2.0 ) * aXi - 1.0 );
72
aWork( 2 ) = 1.0 - aXi * ( 2.0 + 3.0 * aXi );
73
aWork( 3 ) = ( 1.0 + aXi) * ( 1.0 + aXi );
74
aWork *= 0.375;
75
aPoint = aPoints * aWork;
76
77
// cleanup point
78
for
( T & tX : aPoint )
79
{
80
if
( std::abs( tX ) <
BELFEM_EPSILON
)
81
{
82
tX = 0.0 ;
83
}
84
}
85
}
86
87
//------------------------------------------------------------------------------
88
}
89
#endif
//BELFEM_FN_BEZIER_HPP
assert.hpp
BELFEM_ASSERT
#define BELFEM_ASSERT(aCheck,...)
Definition
assert.hpp:244
cl_Matrix.hpp
cl_Vector.hpp
belfem::Matrix
Dense column-major matrix.
Definition
cl_BZ_Matrix.hpp:28
belfem::Matrix::n_rows
size_t n_rows() const
Definition
cl_AR_Matrix.hpp:205
belfem::Matrix::n_cols
size_t n_cols() const
Definition
cl_AR_Matrix.hpp:213
belfem::Vector
Column vector.
Definition
cl_BZ_Vector.hpp:41
belfem::Vector::length
size_t length() const
get the length of the vector
Definition
cl_AR_Vector.hpp:257
belfem
USER GUIDES:
Definition
cl_Capacitor.cpp:16
belfem::cubic_bezier
void cubic_bezier(const Matrix< T > &aPoints, Vector< T > &aWork, const T &aXi, Vector< T > &aPoint)
Definition
fn_cubic_bezier.hpp:26
belfem::cubic_bezier_derivative
void cubic_bezier_derivative(const Matrix< T > &aPoints, Vector< T > &aWork, const T &aXi, Vector< T > &aPoint)
Definition
fn_cubic_bezier.hpp:58
belfem::BELFEM_EPSILON
constexpr real BELFEM_EPSILON
Definition
typedefs.hpp:90
src
math
tools
fn_cubic_bezier.hpp
Generated by
1.18.0