/src/test/aa_regress.c

https://github.com/golems/amino · C · 93 lines · 40 code · 11 blank · 42 comment · 0 complexity · 56c00b68d4c81cdea454c2f414e82513 MD5 · raw file

  1. /* -*- mode: C; c-basic-offset: 4 -*- */
  2. /* ex: set shiftwidth=4 tabstop=4 expandtab: */
  3. /*
  4. * Copyright (c) 2010-2013, Georgia Tech Research Corporation
  5. * All rights reserved.
  6. *
  7. * Author(s): Neil T. Dantam <ntd@gatech.edu>
  8. * Georgia Tech Humanoid Robotics Lab
  9. * Under Direction of Prof. Mike Stilman <mstilman@cc.gatech.edu>
  10. *
  11. *
  12. * This file is provided under the following "BSD-style" License:
  13. *
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * * Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * * Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  28. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  29. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  32. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  35. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  36. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #include "amino.h"
  43. #include "amino/test.h"
  44. static void rotmat_axang() {
  45. /* Had some numerical stability issues */
  46. double q[4] = {0.538444,0.141454,0.510387,0.655419};
  47. double R[9];
  48. aa_tf_quat2rotmat(q, R); // get rotation matrix
  49. double qr[4];
  50. aa_tf_rotmat2quat(R, qr); // convert to quaternion
  51. aveq("quat", 4, q, qr, .001);
  52. double vr[3], vq[3]; // get rotation vectors
  53. aa_tf_quat2rotvec(q, vq);
  54. aa_tf_rotmat2rotvec(R, vr);
  55. aveq("vec", 3, vq, vr, .001);
  56. double qvr[4], qvq[4]; // convert back to quaternions
  57. aa_tf_rotvec2quat( vq, qvq );
  58. aa_tf_rotvec2quat( vr, qvr );
  59. aveq("quat2", 4, qvq, qvr, .001);
  60. }
  61. static void slerp() {
  62. double q[4], q1[4], u;
  63. aa_tf_qurand(q);
  64. u = aa_frand();
  65. aa_tf_qslerp(u, q, q, q1);
  66. aveq( "slerp-equiv", 4, q1, q, 1e-8 );
  67. aa_tf_qslerpalg(u, q, q, q1);
  68. aveq( "slerpalg-equiv", 4, q1, q, 1e-8 );
  69. }
  70. static void rotmat( void ) {
  71. double R0[9] = { 0, 1, 0,
  72. 0, 0, 1,
  73. 1, 0, 0 };
  74. assert(aa_tf_isrotmat(R0));
  75. }
  76. int main() {
  77. srand((unsigned int)time(NULL)); // might break in 2038
  78. aa_test_ulimit();
  79. rotmat_axang();
  80. slerp();
  81. rotmat();
  82. }