misc.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*************************************************************************
  2. * *
  3. * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
  4. * All rights reserved. Email: [email protected] Web: www.q12.org *
  5. * *
  6. * This library is free software; you can redistribute it and/or *
  7. * modify it under the terms of EITHER: *
  8. * (1) The GNU Lesser General Public License as published by the Free *
  9. * Software Foundation; either version 2.1 of the License, or (at *
  10. * your option) any later version. The text of the GNU Lesser *
  11. * General Public License is included with this library in the *
  12. * file LICENSE.TXT. *
  13. * (2) The BSD-style license that is included with this library in *
  14. * the file LICENSE-BSD.TXT. *
  15. * *
  16. * This library is distributed in the hope that it will be useful, *
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
  19. * LICENSE.TXT and LICENSE-BSD.TXT for more details. *
  20. * *
  21. *************************************************************************/
  22. /* miscellaneous math functions. these are mostly useful for testing */
  23. #ifndef _ODE_MISC_H_
  24. #define _ODE_MISC_H_
  25. #include <ode/common.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /* return 1 if the random number generator is working. */
  30. ODE_API int dTestRand(void);
  31. /* return next 32 bit random number. this uses a not-very-random linear
  32. * congruential method.
  33. */
  34. ODE_API unsigned long dRand(void);
  35. /* get and set the current random number seed. */
  36. ODE_API unsigned long dRandGetSeed(void);
  37. ODE_API void dRandSetSeed (unsigned long s);
  38. /* return a random integer between 0..n-1. the distribution will get worse
  39. * as n approaches 2^32.
  40. */
  41. ODE_API int dRandInt (int n);
  42. /* return a random real number between 0..1 */
  43. ODE_API dReal dRandReal(void);
  44. /* print out a matrix */
  45. ODE_API void dPrintMatrix (const dReal *A, int n, int m, const char *fmt, FILE *f);
  46. /* make a random vector with entries between +/- range. A has n elements. */
  47. ODE_API void dMakeRandomVector (dReal *A, int n, dReal range);
  48. /* make a random matrix with entries between +/- range. A has size n*m. */
  49. ODE_API void dMakeRandomMatrix (dReal *A, int n, int m, dReal range);
  50. /* clear the upper triangle of a square matrix */
  51. ODE_API void dClearUpperTriangle (dReal *A, int n);
  52. /* return the maximum element difference between the two n*m matrices */
  53. ODE_API dReal dMaxDifference (const dReal *A, const dReal *B, int n, int m);
  54. /* return the maximum element difference between the lower triangle of two
  55. * n*n matrices */
  56. ODE_API dReal dMaxDifferenceLowerTriangle (const dReal *A, const dReal *B, int n);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #ifdef __cplusplus
  61. static inline void dPrintMatrix (const dReal *A, int n, int m, const char *fmt="%10.4f ") { dPrintMatrix(A, n, m, fmt, stdout); }
  62. #endif
  63. #endif