#ifndef GO_MATH_H
#define GO_MATH_H
#include <stddef.h>
#include "rtapi_math.h"
#include <float.h>
#include "gotypes.h"
#define go_sq(x) ((x)*(x))
#define go_cub(x) ((x)*(x)*(x))
#define go_qua(x) ((x)*(x)*(x)*(x))
extern void go_sincos(go_real x, go_real * s, go_real * c);
extern go_real go_cbrt(go_real x);
#ifdef M_PI
#define GO_PI M_PI
#else
#define GO_PI 3.14159265358979323846
#endif
#define GO_2_PI (2.0*GO_PI)
#ifdef M_PI_2
#define GO_PI_2 M_PI_2
#else
#define GO_PI_2 1.57079632679489661923
#endif
#ifdef M_PI_4
#define GO_PI_4 M_PI_4
#else
#define GO_PI_4 0.78539816339744830962
#endif
#define GO_TO_DEG(rad) ((rad)*57.295779513082323)
#define GO_TO_RAD(deg) ((deg)*0.0174532925199432952)
#define GO_TRAN_CLOSE(x,y) (fabs((x)-(y)) < GO_REAL_EPSILON)
#define GO_TRAN_SMALL(x) (fabs(x) < GO_REAL_EPSILON)
#define GO_ROT_CLOSE(x,y) (fabs((x)-(y)) < GO_REAL_EPSILON)
#define GO_ROT_SMALL(x) (fabs(x) < GO_REAL_EPSILON)
#define GO_CLOSE(x,y) (fabs((x)-(y)) < GO_REAL_EPSILON)
#define GO_SMALL(x) (fabs(x) < GO_REAL_EPSILON)
typedef struct {
go_real x;
go_real y;
go_real z;
} go_cart;
typedef struct {
go_real theta;
go_real phi;
go_real r;
} go_sph;
typedef struct {
go_real theta;
go_real r;
go_real z;
} go_cyl;
typedef struct {
go_real x;
go_real y;
go_real z;
} go_rvec;
typedef struct {
go_cart x;
go_cart y;
go_cart z;
} go_mat;
typedef struct {
go_real s;
go_real x;
go_real y;
go_real z;
} go_quat;
typedef struct {
go_real z;
go_real y;
go_real zp;
} go_zyz;
typedef struct {
go_real z;
go_real y;
go_real x;
} go_zyx;
typedef struct {
go_real r;
go_real p;
go_real y;
} go_rpy;
typedef struct {
go_cart tran;
go_quat rot;
} go_pose;
typedef struct {
go_cart v;
go_cart w;
} go_screw;
extern go_pose
go_pose_this(go_real x, go_real y, go_real z,
go_real rs, go_real rx, go_real ry, go_real rz);
extern go_cart
go_cart_zero(void);
extern go_quat
go_quat_identity(void);
extern go_pose
go_pose_identity(void);
typedef struct {
go_cart tran;
go_mat rot;
} go_hom;
typedef struct {
go_cart point;
go_cart direction;
} go_line;
typedef struct {
go_cart normal;
go_real d;
} go_plane;
extern int go_line_from_point_direction(const go_cart * point, const go_cart * direction, go_line * line);
extern int go_line_from_points(const go_cart * point1, const go_cart * point2, go_line * line);
extern int go_line_from_planes(const go_plane * plane1, const go_plane * plane2, go_line * line);
extern go_flag go_line_line_compare(const go_line * line1, const go_line * line2);
extern int go_line_evaluate(const go_line * line, go_real d, go_cart * point);
extern int go_point_line_distance(const go_cart * point, const go_line * line, go_real * distance);
extern int go_point_line_proj(const go_cart * point, const go_line * line, go_cart * pout);
extern int go_point_plane_proj(const go_cart * point, const go_plane * plane, go_cart * proj);
extern int go_line_plane_proj(const go_line * line, const go_plane * plane, go_line * proj);
extern int go_plane_from_point_normal(const go_cart * point, const go_cart * normal, go_plane * plane);
extern int go_plane_from_abcd(go_real A, go_real B, go_real C, go_real D, go_plane * plane);
extern int go_plane_from_points(const go_cart * point1, const go_cart * point2, const go_cart * point3, go_plane * plane);
extern int go_plane_from_point_line(const go_cart * point, const go_line * line, go_plane * plane);
extern go_flag go_plane_plane_compare(const go_plane * plane1, const go_plane * plane2);
extern int go_point_plane_distance(const go_cart * point, const go_plane * plane, go_real * distance);
extern int go_plane_evaluate(const go_plane * plane, go_real u, go_real v, go_cart * point);
extern int go_line_plane_intersect(const go_line * line, const go_plane * plane, go_cart * point, go_real * distance);
extern int go_cart_sph_convert(const go_cart *, go_sph *);
extern int go_cart_cyl_convert(const go_cart *, go_cyl *);
extern int go_sph_cart_convert(const go_sph *, go_cart *);
extern int go_sph_cyl_convert(const go_sph *, go_cyl *);
extern int go_cyl_cart_convert(const go_cyl *, go_cart *);
extern int go_cyl_sph_convert(const go_cyl *, go_sph *);
extern int go_rvec_quat_convert(const go_rvec *, go_quat *);
extern int go_rvec_mat_convert(const go_rvec *, go_mat *);
extern int go_rvec_zyz_convert(const go_rvec *, go_zyz *);
extern int go_rvec_zyx_convert(const go_rvec *, go_zyx *);
extern int go_rvec_rpy_convert(const go_rvec *, go_rpy *);
extern int go_quat_rvec_convert(const go_quat *, go_rvec *);
extern int go_quat_mat_convert(const go_quat *, go_mat *);
extern int go_quat_zyz_convert(const go_quat *, go_zyz *);
extern int go_quat_zyx_convert(const go_quat *, go_zyx *);
extern int go_quat_rpy_convert(const go_quat *, go_rpy *);
extern int go_mat_rvec_convert(const go_mat *, go_rvec *);
extern int go_mat_quat_convert(const go_mat *, go_quat *);
extern int go_mat_zyz_convert(const go_mat *, go_zyz *);
extern int go_mat_zyx_convert(const go_mat *, go_zyx *);
extern int go_mat_rpy_convert(const go_mat *, go_rpy *);
extern int go_zyz_rvec_convert(const go_zyz *, go_rvec *);
extern int go_zyz_quat_convert(const go_zyz *, go_quat *);
extern int go_zyz_mat_convert(const go_zyz *, go_mat *);
extern int go_zyz_zyx_convert(const go_zyz *, go_zyx *);
extern int go_zyz_rpy_convert(const go_zyz *, go_rpy *);
extern int go_zyx_rvec_convert(const go_zyx *, go_rvec *);
extern int go_zyx_quat_convert(const go_zyx *, go_quat *);
extern int go_zyx_mat_convert(const go_zyx *, go_mat *);
extern int go_zyx_zyz_convert(const go_zyx *, go_zyz *);
extern int go_zyx_rpy_convert(const go_zyx *, go_rpy *);
extern int go_rpy_rvec_convert(const go_rpy *, go_rvec *);
extern int go_rpy_quat_convert(const go_rpy *, go_quat *);
extern int go_rpy_mat_convert(const go_rpy *, go_mat *);
extern int go_rpy_zyz_convert(const go_rpy *, go_zyz *);
extern int go_rpy_zyx_convert(const go_rpy *, go_zyx *);
extern int go_pose_hom_convert(const go_pose *, go_hom *);
extern int go_hom_pose_convert(const go_hom *, go_pose *);
extern int go_cart_rvec_convert(const go_cart * cart, go_rvec * rvec);
extern int go_rvec_cart_convert(const go_rvec * rvec, go_cart * cart);
extern go_flag go_cart_cart_compare(const go_cart *, const go_cart *);
extern int go_cart_cart_dot(const go_cart *, const go_cart *,
go_real *);
extern int go_cart_cart_cross(const go_cart *, const go_cart *,
go_cart *);
extern int go_cart_mag(const go_cart *, go_real *);
extern int go_cart_magsq(const go_cart *, go_real *);
extern go_flag go_cart_cart_par(const go_cart *, const go_cart *);
extern go_flag go_cart_cart_perp(const go_cart *, const go_cart *);
extern int go_cart_cart_disp(const go_cart * v1,
const go_cart * v2,
go_real * disp);
extern int go_cart_cart_add(const go_cart *, const go_cart *,
go_cart *);
extern int go_cart_cart_sub(const go_cart *, const go_cart *,
go_cart *);
extern int go_cart_scale_mult(const go_cart *, go_real, go_cart *);
extern int go_cart_neg(const go_cart *, go_cart *);
extern int go_cart_unit(const go_cart *, go_cart *);
extern int go_cart_cart_rot(const go_cart * v1,
const go_cart * v2,
go_quat * quat);
extern int go_cart_cart_proj(const go_cart * v1, const go_cart * v2,
go_cart * vout);
extern int go_cart_plane_proj(const go_cart *, const go_cart *,
go_cart *);
extern int go_cart_cart_angle(const go_cart *, const go_cart *,
go_real *);
extern int go_cart_normal(const go_cart * v, go_cart * vout);
extern int go_cart_centroid(const go_cart * varray,
go_integer num,
go_cart * centroid);
extern int go_cart_centroidize(const go_cart * vinarray,
go_integer num,
go_cart * centroid,
go_cart * voutarray);
extern int go_cart_cart_pose(const go_cart *, const go_cart *,
go_cart *, go_cart *,
go_integer, go_pose *);
int go_cart_trilaterate(const go_cart * c1,
const go_cart * c2,
const go_cart * c3,
go_real l1,
go_real l2,
go_real l3,
go_cart * p1,
go_cart * p2);
extern go_flag go_quat_quat_compare(const go_quat *, const go_quat *);
extern int go_quat_mag(const go_quat *, go_real *);
extern int go_quat_unit(const go_quat * q, go_quat * qout);
extern int go_quat_norm(const go_quat *, go_quat *);
extern int go_quat_inv(const go_quat *, go_quat *);
extern go_flag go_quat_is_norm(const go_quat *);
extern int go_quat_scale_mult(const go_quat *, go_real, go_quat *);
extern int go_quat_quat_mult(const go_quat *, const go_quat *,
go_quat *);
extern int go_quat_cart_mult(const go_quat *, const go_cart *,
go_cart *);
extern go_flag go_rvec_rvec_compare(const go_rvec * r1, const go_rvec * r2);
extern int go_rvec_scale_mult(const go_rvec *, go_real, go_rvec *);
extern int go_mat_norm(const go_mat * m, go_mat * mout);
extern go_flag go_mat_is_norm(const go_mat *);
extern int go_mat_inv(const go_mat *, go_mat *);
extern int go_mat_cart_mult(const go_mat *, const go_cart *, go_cart *);
extern int go_mat_mat_mult(const go_mat *, const go_mat *, go_mat *);
extern go_flag go_pose_pose_compare(const go_pose *, const go_pose *);
extern int go_pose_inv(const go_pose *, go_pose *);
extern int go_pose_cart_mult(const go_pose *, const go_cart *, go_cart *);
extern int go_pose_pose_mult(const go_pose *, const go_pose *, go_pose *);
extern int go_pose_scale_mult(const go_pose *, go_real, go_pose *);
extern int
go_pose_pose_interp(go_real t1,
const go_pose * p1,
go_real t2,
const go_pose * p2,
go_real t3,
go_pose * p3);
extern int go_hom_inv(const go_hom *, go_hom *);
extern int go_pose_screw_mult(const go_pose * pose, const go_screw * screw, go_screw * out);
typedef go_real go_vector;
typedef struct {
go_integer rows;
go_integer cols;
go_real ** el;
go_real ** elcpy;
go_real * v;
go_integer * index;
} go_matrix;
#define GO_MATRIX_DECLARE(M,Mspace,_rows,_cols) \
go_matrix M = {0, 0, 0, 0, 0, 0}; \
struct { \
go_real * el[_rows]; \
go_real * elcpy[_rows]; \
go_real stg[_rows][_cols]; \
go_real stgcpy[_rows][_cols]; \
go_real v[_rows]; \
go_integer index[_rows]; \
} Mspace
#define go_matrix_init(M,Mspace,_rows,_cols) \
M.el = Mspace.el; \
M.elcpy = Mspace.elcpy; \
for (M.rows = 0; M.rows < (_rows); M.rows++) { \
M.el[M.rows] = Mspace.stg[M.rows]; \
M.elcpy[M.rows] = Mspace.stgcpy[M.rows]; \
} \
M.rows = (_rows); \
M.cols = (_cols); \
M.v = Mspace.v; \
M.index = Mspace.index
extern go_real
go_get_singular_epsilon(void);
extern int
go_set_singular_epsilon(go_real epsilon);
extern int
ludcmp(go_real ** a,
go_real * scratchrow,
go_integer n,
go_integer * indx,
go_real * d);
extern int
lubksb(go_real ** a,
go_integer n,
go_integer * indx,
go_real * b);
extern int
go_cart_vector_convert(const go_cart * c,
go_vector * v);
extern int
go_vector_cart_convert(const go_real * v,
go_cart * c);
extern int
go_quat_matrix_convert(const go_quat * quat,
go_matrix * matrix);
extern int
go_mat_matrix_convert(const go_mat * mat,
go_matrix * matrix);
extern int
go_matrix_matrix_add(const go_matrix * a,
const go_matrix * b,
go_matrix * apb);
extern int
go_matrix_matrix_copy(const go_matrix * src,
go_matrix * dst);
extern int
go_matrix_matrix_mult(const go_matrix * a,
const go_matrix * b,
go_matrix * ab);
extern int
go_matrix_vector_mult(const go_matrix * a,
const go_vector * v,
go_vector * av);
extern int
go_matrix_vector_cross(const go_matrix * a,
const go_vector * v,
go_matrix * axv);
extern int
go_matrix_transpose(const go_matrix * a,
go_matrix * at);
extern int
go_matrix_inv(const go_matrix * a,
go_matrix * ainv);
extern int go_mat3_inv(const go_real a[3][3],
go_real ainv[3][3]);
extern int go_mat3_mat3_mult(const go_real a[3][3],
const go_real b[3][3],
go_real axb[3][3]);
extern int go_mat3_vec3_mult(const go_real a[3][3],
const go_real v[3],
go_real axv[3]);
extern int go_mat4_inv(const go_real a[4][4],
go_real ainv[4][4]);
extern int go_mat4_mat4_mult(const go_real a[4][4],
const go_real b[4][4],
go_real axb[4][4]);
extern int go_mat4_vec4_mult(const go_real a[4][4],
const go_real v[4],
go_real axv[4]);
extern int go_mat6_inv(const go_real a[6][6],
go_real ainv[6][6]);
extern int go_mat6_mat6_mult(const go_real a[6][6],
const go_real b[6][6],
go_real axb[6][6]);
extern int go_mat6_vec6_mult(const go_real a[6][6],
const go_real v[6],
go_real axv[6]);
typedef struct {
go_real a;
go_real alpha;
go_real d;
go_real theta;
} go_dh;
typedef struct {
go_cart base;
go_cart platform;
go_real d;
} go_pk;
typedef struct {
go_pose pose;
} go_pp;
enum {
GO_LINK_DH = 1,
GO_LINK_PK,
GO_LINK_PP
};
#define go_link_to_string(L) \
(L) == GO_LINK_DH ? "DH" : \
(L) == GO_LINK_PK ? "PK" : \
(L) == GO_LINK_PP ? "PP" : "None"
typedef struct {
union {
go_dh dh;
go_pk pk;
go_pp pp;
} u;
go_flag type;
go_flag quantity;
} go_link;
extern int go_dh_pose_convert(const go_dh * dh, go_pose * pose);
extern int go_pose_dh_convert(const go_pose * pose, go_dh * dh);
extern int go_link_joint_set(const go_link * link, go_real joint, go_link * linkout);
extern int go_link_pose_build(const go_link * links, go_integer num, go_pose * pose);
typedef struct {
go_real re;
go_real im;
} go_complex;
extern go_complex go_complex_add(go_complex z1, go_complex z2);
extern go_complex go_complex_sub(go_complex z1, go_complex z2);
extern go_complex go_complex_mult(go_complex z1, go_complex z2);
extern go_complex go_complex_div(go_complex z1, go_complex z2, int * result);
extern go_complex go_complex_scale(go_complex z, go_real scale);
extern go_real go_complex_mag(go_complex z);
extern go_real go_complex_arg(go_complex z);
extern void go_complex_sqrt(go_complex z, go_complex * z1, go_complex * z2);
extern void go_complex_cbrt(go_complex z, go_complex * z1, go_complex * z2, go_complex * z3);
typedef struct {
go_real a;
go_real b;
} go_quadratic;
typedef struct {
go_real a;
go_real b;
go_real c;
} go_cubic;
typedef struct {
go_real a;
go_real b;
go_real c;
go_real d;
} go_quartic;
extern int go_quadratic_solve(const go_quadratic * quad,
go_complex * z1,
go_complex * z2);
extern int go_cubic_solve(const go_cubic * cub,
go_complex * z1,
go_complex * z2,
go_complex * z3);
extern int go_quartic_solve(const go_quartic * quart,
go_complex * z1,
go_complex * z2,
go_complex * z3,
go_complex * z4);
extern int go_tridiag_reduce(go_real ** a,
go_integer n,
go_real * d,
go_real * e);
extern int go_tridiag_ql(go_real * d,
go_real * e,
go_integer n,
go_real ** z);
#endif