1 | /** |
---|
2 | * Scattering model for an ellipsoid |
---|
3 | * @author: Mathieu Doucet / UTK |
---|
4 | */ |
---|
5 | |
---|
6 | #include "ellipsoid.h" |
---|
7 | #include "libCylinder.h" |
---|
8 | #include <math.h> |
---|
9 | #include <stdio.h> |
---|
10 | |
---|
11 | /** |
---|
12 | * Test kernel for validation |
---|
13 | * |
---|
14 | * @param q: q-value |
---|
15 | * @param r_small: small axis length |
---|
16 | * @param r_long: rotation axis length |
---|
17 | * @param angle: angle between rotation axis and q vector |
---|
18 | * @return: oriented kernel value |
---|
19 | */ |
---|
20 | double kernel(double q, double r_small, double r_long, double angle) { |
---|
21 | double length; |
---|
22 | double sin_alpha; |
---|
23 | double cos_alpha; |
---|
24 | double sph_func; |
---|
25 | |
---|
26 | sin_alpha = sin(angle); |
---|
27 | cos_alpha = cos(angle); |
---|
28 | |
---|
29 | // Modified length for phase |
---|
30 | length = r_small*sqrt(sin_alpha*sin_alpha + |
---|
31 | r_long*r_long/(r_small*r_small)*cos_alpha*cos_alpha); |
---|
32 | |
---|
33 | // Spherical scattering ampliture, with modified length for ellipsoid |
---|
34 | sph_func = 3*( sin(q*length) - q*length*cos(q*length) ) / (q*q*q*length*length*length); |
---|
35 | |
---|
36 | return sph_func*sph_func; |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * Function to evaluate 1D scattering function |
---|
41 | * @param pars: parameters of the ellipsoid |
---|
42 | * @param q: q-value |
---|
43 | * @return: function value |
---|
44 | */ |
---|
45 | double ellipsoid_analytical_1D(EllipsoidParameters *pars, double q) { |
---|
46 | double dp[5]; |
---|
47 | |
---|
48 | dp[0] = pars->scale; |
---|
49 | dp[1] = pars->radius_a; |
---|
50 | dp[2] = pars->radius_b; |
---|
51 | dp[3] = pars->contrast; |
---|
52 | dp[4] = pars->background; |
---|
53 | |
---|
54 | return EllipsoidForm(dp, q); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Function to evaluate 2D scattering function |
---|
59 | * @param pars: parameters of the ellipsoid |
---|
60 | * @param q: q-value |
---|
61 | * @return: function value |
---|
62 | */ |
---|
63 | double ellipsoid_analytical_2DXY(EllipsoidParameters *pars, double qx, double qy) { |
---|
64 | double q; |
---|
65 | q = sqrt(qx*qx+qy*qy); |
---|
66 | return ellipsoid_analytical_2D_scaled(pars, q, qx/q, qy/q); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Function to evaluate 2D scattering function |
---|
71 | * @param pars: parameters of the ellipsoid |
---|
72 | * @param q: q-value |
---|
73 | * @param phi: angle phi |
---|
74 | * @return: function value |
---|
75 | */ |
---|
76 | double ellipsoid_analytical_2D(EllipsoidParameters *pars, double q, double phi) { |
---|
77 | return ellipsoid_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); |
---|
78 | } |
---|
79 | |
---|
80 | /** |
---|
81 | * Function to evaluate 2D scattering function |
---|
82 | * @param pars: parameters of the ellipsoid |
---|
83 | * @param q: q-value |
---|
84 | * @param q_x: q_x / q |
---|
85 | * @param q_y: q_y / q |
---|
86 | * @return: function value |
---|
87 | */ |
---|
88 | double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) { |
---|
89 | double cyl_x, cyl_y, cyl_z; |
---|
90 | double q_z, lenq; |
---|
91 | double theta, alpha, f, vol, sin_val, cos_val; |
---|
92 | double answer; |
---|
93 | |
---|
94 | // Ellipsoid orientation |
---|
95 | cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); |
---|
96 | cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); |
---|
97 | cyl_z = cos(pars->axis_theta); |
---|
98 | |
---|
99 | // q vector |
---|
100 | q_z = 0; |
---|
101 | |
---|
102 | // Compute the angle btw vector q and the |
---|
103 | // axis of the cylinder |
---|
104 | cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; |
---|
105 | |
---|
106 | // The following test should always pass |
---|
107 | if (fabs(cos_val)>1.0) { |
---|
108 | printf("ellipsoid_ana_2D: Unexpected error: cos(alpha)>1\n"); |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|
112 | // Angle between rotation axis and q vector |
---|
113 | alpha = acos( cos_val ); |
---|
114 | |
---|
115 | // Call the IGOR library function to get the kernel |
---|
116 | answer = EllipsoidKernel(q, pars->radius_a, pars->radius_b, cos_val); |
---|
117 | |
---|
118 | // Multiply by contrast^2 |
---|
119 | answer *= pars->contrast*pars->contrast; |
---|
120 | |
---|
121 | //normalize by cylinder volume |
---|
122 | vol = 4.0/3.0 * acos(-1.0) * pars->radius_b * pars->radius_b * pars->radius_a; |
---|
123 | answer *= vol; |
---|
124 | |
---|
125 | //convert to [cm-1] |
---|
126 | answer *= 1.0e8; |
---|
127 | |
---|
128 | //Scale |
---|
129 | answer *= pars->scale; |
---|
130 | |
---|
131 | // add in the background |
---|
132 | answer += pars->background; |
---|
133 | |
---|
134 | return answer; |
---|
135 | } |
---|