Free Electron
MatrixBezier.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __geometry_MatrixBezier_h__
8 #define __geometry_MatrixBezier_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief solve B = A^^power, where A is a matrix
17 
18  @ingroup geometry
19 
20  This version uses a Quadratic Bezier approximation.
21 
22  The first column of the matrix is presumed to be the tangent.
23 
24  The power should be a real number between 0 and 1.
25 
26  For a proper matrix power function, see MatrixPower.
27 
28 *//***************************************************************************/
29 template <typename MATRIX>
31 {
32  public:
33  MatrixBezier(void) {}
34 
35  template <typename T>
36  void solve(MATRIX& B, const MATRIX& A, T a_power) const;
37 };
38 
39 template <typename MATRIX>
40 template <typename T>
41 inline void MatrixBezier<MATRIX>::solve(MATRIX& B, const MATRIX& A,
42  T a_power) const
43 {
44  const T linearity=0.45; //* TODO param
45 
46  const Vector<3,T>& rTranslation=A.translation();
47  const T distance=magnitude(rTranslation);
48 
49  const MATRIX rotation(a_power*SpatialQuaternion(A));
50 
51  const T power1=T(1)-a_power;
52  const T xStart=distance*a_power;
53  const T xFull= -distance*power1;
54 
55  //* transform of X-only vector
56  const Vector<3,T> locTip=xFull*A.column(0)+rTranslation;
57 
58  const Vector<3,T> locBlend(
59  locTip[0]*a_power+xStart*power1,
60  locTip[1]*a_power,
61  locTip[2]*a_power);
62 
63  const Vector<3,T> locLinear=rTranslation*a_power;
64  const Vector<3,T> locMix=locLinear*linearity+locBlend*(1.0-linearity);
65 
66  //* rotation of unit axes
67  const Vector<3,T>& xArmBlend=rotation.column(0);
68  const Vector<3,T>& yArmBlend=rotation.column(1);
69 
70  makeFrameTangentX(B,locMix,xArmBlend,yArmBlend);
71 }
72 
73 } /* namespace ext */
74 } /* namespace fe */
75 
76 #endif /* __geometry_MatrixBezier_h__ */
77 
kernel
Definition: namespace.dox:3
solve B = A^^power, where A is a matrix
Definition: MatrixBezier.h:30