next up previous contents
Next: 3D Matrix Algebra Functions Up: 2D and 3D vector Previous: 3D Vector Algebra Functions   Contents

3D Vector Geometry

Functions for doing 3D geometry of points lines, planes and circles using the following vector descriptions:

typedef struct vec3
{
    Ts_id ts_id;                /* Tina structure identifier */
    float   el[3];              /* point in 3D coordinates */
} Vec3;

typedef struct line3
{
    Ts_id ts_id;                /* Tina structure identifier */
    unsigned int type;
    unsigned int label;
    struct vec3 p1,p2;         /* end points */
    struct vec3 p;             /* point on the line */
    struct vec3 v;             /* direction vector */
    float length;
    struct list *props;
} Line3;

typedef struct plane
{
    Ts_id ts_id;                /* Tina structure identifier */
    unsigned int type;
    unsigned int label;
    struct vec3 p;             /* a point on the plane */
    struct vec3 n;             /* normal to plane */
    struct list *props;
} Plane;

typedef struct conic
{
    Ts_id ts_id;                /* Tina structure identifier */
    unsigned int type;
    unsigned int label;
    int filler1;
    double a, b, c, d, e, f;   /* algebraic formula */
    double theta, alpha, beta;
    struct vec2 center;
    int filler2;
    double t1, t2;       /* conic params of p1 and p2 */
    int branch;          /* for hyperbola only */
    List *props;         /* property list */
} Conic;

Vec3 vec3_midpoint(Vec3 q1, Vec3 q2)
Returns midpoint of line from q1 to q2.

Vec3 vec3_projperp(Vec3 u, Vec3 v)
Returns projection of u perpendicular to unit vector v.

Vec3 vec3_projpar(Vec3 u, Vec3 v)
Returns projection of u parallel to unit vector v.

Vec3 vec3_proj_on_line(Vec3 q, Vec3 l, Vec3 v)
Returns perpendicular projection of point q onto line (l, v) (i.e. closest point on line).

Vec3 vec3_proj_on_plane(Vec3 q, Vec3 p, Vec3 n)
Returns perpendicular projection of point q onto plane (p, n) (i.e. closest point on plane).

Vec3 vec3_proj_line_on_plane(Vec3 l1, Vec3 v1, Vec3 p, Vec3 n, Vec3 *l2,
                             Vec3 *v2)
Sets line (*l2, *v2) which is perpendicular projection of line (l1, v1) onto plane (p, n).

Vec3 vec3_closest_lines(Vec3 l1, Vec3 v1, Vec3 l2, Vec3 v2)
Returns point on line (l1, v2) closest to line (l2, v2).

Vec3 vec3_inter_lines(Vec3 l1, Vec3 v1, Vec3 l2, Vec3 v2)
Returns point closest to two lines (i.e. their intersection if it exists).

Vec3 vec3_inter_line_plane(Vec3 l, Vec3 v, Vec3 p, Vec3 n)
Returns point of intersection of line (l, v) with plane (p, n).

void vec3_inter_planes(Vec3 p1, Vec3 n1, Vec3 p2, Vec3 n2, Vec3 *l, Vec3 *v)
Sets line (*l, *v) of intersection of two planes (p1, n1), (p2, n2).

void    vec3_join_2_points(Vec3 q1, Vec3 q2, Vec3 * l, Vec3 * v)
Sets line (*l, *v) joining two points q1, q2, *l is midpoint, *v points from q1 to q2.

void    vec3_join_3_points(Vec3 q1, Vec3 q2, Vec3 q3, Vec3 * p, Vec3 * n)
Sets plane (*p, *n) though 3 points q1, q2, q3. *p is centroid of points.

void    vec3_join_point_line(Vec3 q, Vec3 l, Vec3 v, Vec3 * p, Vec3 * n)
Sets plane (*p, *n) though points q, and line (l, v). *p is at midpoint of p and l.

void    vec3_join_lines(Vec3 l1, Vec3 v1, Vec3 l2, Vec3 v2, Vec3 * p, Vec3 * n)
Sets plane (*p, *n) though two lines (l1, v1) and (l2, v2). If they are not coplanar, plane is parallel to both lines, and passes through point of closest approach (*p is not chosen as closest approach).

double  vec3_dist_point_plane(Vec3 q, Vec3 p, Vec3 n)
Returns perpendicular distance of point q from plane (p, n).

double  vec3_dist_point_line(Vec3 q, Vec3 l, Vec3 v)
Returns perpendicular distance of point q from line (l, v).

double  vec3_dist_lines(Vec3 l1, Vec3 v1, Vec3 l2, Vec3 v2)
Returns perpendicular distance between lines (l1, v1), (l2, v2).

void    vec3_circ_3_points(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 * centre,
                           Vec3 * normal, double *radius)
Sets circle (*c, *n, *r) through three points p1, p2, p3, (normal gives correct ordering for right handed rotations).

Bool    vec3_collinear(Vec3 p1, Vec3 p2, Vec3 q1, Vec3 q2,
                       double dotth1, double dotth2)
Checks whether line segments with endpoints (p1, p2) and (q1, q2) are collinear. This routine is a useful starting point but makes no attempt to model any inderlying statistics properly and should only be used with caution or preferably re-written for your own statistical model.

double  vec3_closest_app(Vec3 p1, Vec3 v1, Vec3 p2, Vec3 v2,
                         Vec3 * c1, Vec3 * c2)
Sets point *q1 on (l1, v1) closest to (l2, v2) and point *q2 on (l2, v2) closest to (l1, v1).

Bool    vec3_parallel(Vec3 v1, Vec3 v2, double dotthres)
Checks for parallelism of unit vectors using a threshold on their dot product. (So dotthres = cosine of angle thresh, e.g. it will be close to 1.0).


next up previous contents
Next: 3D Matrix Algebra Functions Up: 2D and 3D vector Previous: 3D Vector Algebra Functions   Contents
root 2017-11-22