BELFEM 0.9.0
Berkeley Lab Finite Element Framework
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
20namespace belfem
21{
22//------------------------------------------------------------------------------
23
24 template < typename T >
25 void
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
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
#define BELFEM_ASSERT(aCheck,...)
Definition assert.hpp:244
Dense column-major matrix.
Definition cl_BZ_Matrix.hpp:28
size_t n_rows() const
Definition cl_AR_Matrix.hpp:205
size_t n_cols() const
Definition cl_AR_Matrix.hpp:213
Column vector.
Definition cl_BZ_Vector.hpp:41
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
USER GUIDES:
Definition cl_Capacitor.cpp:16
void cubic_bezier(const Matrix< T > &aPoints, Vector< T > &aWork, const T &aXi, Vector< T > &aPoint)
Definition fn_cubic_bezier.hpp:26
void cubic_bezier_derivative(const Matrix< T > &aPoints, Vector< T > &aWork, const T &aXi, Vector< T > &aPoint)
Definition fn_cubic_bezier.hpp:58
constexpr real BELFEM_EPSILON
Definition typedefs.hpp:90