1 #include <gsl/gsl_math.h>
2 #include <gsl/gsl_vector.h>
3 #include <gsl/gsl_sf_trig.h>
5 #include <hkl/hkl-pseudoaxis-K4CV.h>
6 #include <hkl/hkl-pseudoaxis-common.h>
8 /***********************/
9 /* numerical functions */
10 /***********************/
12 static int bissector_f1(const gsl_vector
*x
, void *params
, gsl_vector
*f
)
14 double komega
, tth
, kappa
, omega
;
16 HklPseudoAxisEngine
*engine
;
17 double const *x_data
= gsl_vector_const_ptr(x
, 0);
18 double *f_data
= gsl_vector_ptr(f
, 0);
22 for(i
=0; i
<x
->size
;++i
)
23 if (gsl_isnan(x_data
[i
]))
26 RUBh_minus_Q(x_data
, params
, f_data
);
30 tth
= gsl_sf_angle_restrict_symm(x_data
[3]);
32 omega
= komega
+ atan(tan(kappa
/2.)*cos(50 * HKL_DEGTORAD
)) + M_PI_2
;
33 omega
= gsl_sf_angle_restrict_pos(omega
);
34 //f_data[3] = tth - 2 * fmod(omega,M_PI);
35 f_data
[3] = tth
- 2*omega
;
40 static int bissector_f2(const gsl_vector
*x
, void *params
, gsl_vector
*f
)
42 double komega
, tth
, kappa
, omega
;
44 HklPseudoAxisEngine
*engine
;
45 double const *x_data
= gsl_vector_const_ptr(x
, 0);
46 double *f_data
= gsl_vector_ptr(f
, 0);
50 for(i
=0; i
<x
->size
;++i
)
51 if (gsl_isnan(x_data
[i
]))
54 RUBh_minus_Q(x_data
, params
, f_data
);
58 tth
= gsl_sf_angle_restrict_symm(x_data
[3]);
60 omega
= komega
+ atan(tan(kappa
/2.)*cos(50 * HKL_DEGTORAD
)) - M_PI_2
;
61 omega
= gsl_sf_angle_restrict_pos(omega
);
62 //f_data[3] = tth - 2 * fmod(omega,M_PI);
63 f_data
[3] = tth
- 2*omega
;
68 /*********************/
69 /* Getter and Setter */
70 /*********************/
72 static int hkl_pseudo_axis_engine_setter_func_bissector(HklPseudoAxisEngine
*engine
,
73 HklGeometry
*geometry
, HklDetector
*detector
,
78 hkl_pseudoAxeEngine_prepare_internal(engine
, geometry
, detector
,
81 res
|= hkl_pseudoAxeEngine_solve_function(engine
, bissector_f1
);
82 res
|= hkl_pseudoAxeEngine_solve_function(engine
, bissector_f2
);
87 /************************/
88 /* K4CV PseudoAxeEngine */
89 /************************/
91 HklPseudoAxisEngine
*hkl_pseudoAxisEngine_new_K4CV_HKL(void)
93 HklPseudoAxisEngine
*self
;
94 HklPseudoAxisEngineGetSet
*getset
;
96 self
= hkl_pseudoAxisEngine_new("hkl", 3, "h", "k", "l");
98 /* hkl get/set bissector */
99 getset
= hkl_pseudo_axis_engine_get_set_new(
101 hkl_pseudo_axis_engine_getter_func_hkl
,
102 hkl_pseudo_axis_engine_setter_func_bissector
,
104 4, "komega", "kappa", "kphi", "tth");
105 hkl_pseudoAxisEngine_add_get_set(self
, getset
);