aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-03-26 22:42:49 +0100
committerThomas White <taw@physics.org>2012-02-22 15:27:22 +0100
commitb730350f342972083bc28195d0042b2485135ee9 (patch)
tree3dc017ebeb1fe5c66f83240498ec5c2a8d1c0ee8 /src/utils.c
parent5ccdcc43256c8bb6efee7e13d84ea868a288dd71 (diff)
More documentation stuff
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 7a27e057..02de3e14 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -166,12 +166,42 @@ int poisson_noise(double expected)
}
+/**
+ * SECTION:quaternion
+ * @short_description: Simple quaternion handling
+ * @title: Quaternion
+ * @section_id:
+ * @see_also:
+ * @include: "utils.h"
+ * @Image:
+ *
+ * There is a simple quaternion structure in CrystFEL. At the moment, it is
+ * only used when simulating patterns, as an argument to %cell_rotate to
+ * orient the unit cell.
+ */
+
+/**
+ * quaternion_modulus:
+ * @q: A %quaternion
+ *
+ * If a quaternion represents a pure rotation, its modulus should be unity.
+ *
+ * Returns: the modulus of the given quaternion.
+ **/
double quaternion_modulus(struct quaternion q)
{
return sqrt(q.w*q.w + q.x*q.x + q.y*q.y + q.z*q.z);
}
+/**
+ * normalise_quaternion:
+ * @q: A %quaternion
+ *
+ * Rescales the quaternion such that its modulus is unity.
+ *
+ * Returns: the normalised version of @q
+ **/
struct quaternion normalise_quaternion(struct quaternion q)
{
double mod;
@@ -188,6 +218,11 @@ struct quaternion normalise_quaternion(struct quaternion q)
}
+/**
+ * random_quaternion:
+ *
+ * Returns: a randomly generated, normalised, quaternion.
+ **/
struct quaternion random_quaternion()
{
struct quaternion q;
@@ -202,6 +237,18 @@ struct quaternion random_quaternion()
}
+/**
+ * quaternion_valid:
+ * @q: A %quaternion
+ *
+ * Checks if the given quaternion is normalised.
+ *
+ * This function performs a nasty floating point comparison of the form
+ * <code>(modulus > 0.999) && (modulus < 1.001)</code>, and so should not be
+ * relied upon to spot anything other than the most obvious input error.
+ *
+ * Returns: 1 if the quaternion is normalised, 0 if not.
+ **/
int quaternion_valid(struct quaternion q)
{
double qmod;
@@ -216,6 +263,15 @@ int quaternion_valid(struct quaternion q)
}
+/**
+ * quat_rot
+ * @q: A vector (in the form of an %rvec)
+ * @z: A %quaternion
+ *
+ * Rotates a vector according to a quaternion.
+ *
+ * Returns: A rotated version of @p.
+ **/
struct rvec quat_rot(struct rvec q, struct quaternion z)
{
struct rvec res;