~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/geomstat/constraint/state_extd.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**@(#)
  2 **/
  3 #include <math.h>
  4 #include <stdio.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 #include <tina/vision.h>
 10 #include <tina/visionfuncs.h>
 11 
 12 /**
 13 GS_END1   : make end1 p
 14 GS_END2   : make end2 p
 15 GS_ENDANY : make nearest end p
 16 GS_ENDOUT : make nearest end p if p is beyond end
 17 GS_ENDNEAR: make nearest end p if p near enough
 18 **/
 19 
 20 int     extend_line_to_point(Vec3 * e1, Vec3 * e2, int dirn, Vec3 p)
 21 {
 22     Vec3    v = {Vec3_id};
 23 
 24     v = vec3_unit(vec3_diff(*e2, *e1));
 25     switch (dirn)
 26     {
 27     case GS_END1:
 28         *e1 = vec3_proj_on_line(p, *e1, v);
 29         return (GS_END1);
 30         break;
 31     case GS_END2:
 32         *e2 = vec3_proj_on_line(p, *e2, v);
 33         return (GS_END1);
 34         break;
 35     case GS_ENDANY:
 36         {
 37             double  t, t1, t2;
 38 
 39             t1 = vec3_dot(v, *e1);
 40             t2 = vec3_dot(v, *e2);
 41             t = (vec3_dot(v, p) - t1) / (t2 - t1);
 42             if (t < 0.5)
 43             {
 44                 *e1 = vec3_proj_on_line(p, *e1, v);
 45                 return (GS_END1);
 46             } else
 47             {
 48                 *e2 = vec3_proj_on_line(p, *e2, v);
 49                 return (GS_END2);
 50             }
 51             break;
 52         }
 53     case GS_ENDOUT:
 54         {
 55             double  t, t1, t2;
 56 
 57             t1 = vec3_dot(v, *e1);
 58             t2 = vec3_dot(v, *e2);
 59             t = (vec3_dot(v, p) - t1) / (t2 - t1);
 60             if (t < 0.0)
 61             {
 62                 *e1 = vec3_proj_on_line(p, *e1, v);
 63                 return (GS_END1);
 64             } else if (t > 1.0)
 65             {
 66                 *e2 = vec3_proj_on_line(p, *e2, v);
 67                 return (GS_END2);
 68             }
 69             break;
 70         }
 71     case GS_ENDNEAR:
 72         {
 73             double  t, t1, t2;
 74 
 75             t1 = vec3_dot(v, *e1);
 76             t2 = vec3_dot(v, *e2);
 77             t = (vec3_dot(v, p) - t1) / (t2 - t1);
 78             if (t < 0.2)
 79             {
 80                 *e1 = vec3_proj_on_line(p, *e1, v);
 81                 return (GS_END1);
 82             } else if (t > 0.8)
 83             {
 84                 *e2 = vec3_proj_on_line(p, *e2, v);
 85                 return (GS_END2);
 86             }
 87             break;
 88         }
 89     }
 90     error("extend_line_to_point: no such extension type", non_fatal);
 91     return (0);
 92 }
 93 
 94 int     extend_line_to_line(Vec3 * e1, Vec3 * e2, int dirn, Vec3 p, Vec3 v)
 95 {
 96     /* BUGFIX l unused */
 97     /* Vec3    u; u = vec3_unit(vec3_diff(*e2, *e1)); Vec3    l; l =
 98      * vec3_closest_lines(*e1, u, p, v); */
 99     return (extend_line_to_point(e1, e2, dirn, p));
100 }
101 
102 int     extend_line_to_plane(Vec3 * e1, Vec3 * e2, int dirn, Vec3 p, Vec3 n)
103 {
104     Vec3    u = {Vec3_id};
105 
106     u = vec3_diff(*e2, *e1);
107     p = vec3_inter_line_plane(*e1, u, p, n);
108     return (extend_line_to_point(e1, e2, dirn, p));
109 }
110 
111 void    state_extend(State * state, int i0, int i1, int dirn)
112 {
113     int     type0, type1;
114 
115     if (state_badpair(state, i0, i1))
116         return;
117 
118     type0 = vector_get(state->type, i0);
119     type1 = vector_get(state->type, i1);
120     (void) geom_reorder(&i0, &i1, &type0, &type1);
121 
122     switch (OPAIR(type0, type1))
123     {
124     case OPAIR(POINT3, LINE3):
125         {
126             Point3 *point = (Point3 *) vector_getp(state->geom, i0);
127             Line3  *line = (Line3 *) vector_getp(state->geom, i1);
128 
129             (void) extend_line_to_point(&line->p1, &line->p2, dirn, point->p);
130             break;
131         }
132     case OPAIR(LINE3, LINE3):
133         {
134             /** on pick list in wrong order **/
135             Line3  *line0 = (Line3 *) vector_getp(state->geom, i1);
136             Line3  *line1 = (Line3 *) vector_getp(state->geom, i0);
137 
138             (void) extend_line_to_line(&line0->p1, &line0->p2, dirn,
139                                        line1->p, line1->v);
140             break;
141         }
142     case OPAIR(LINE3, PLANE):
143         {
144             Line3  *line = (Line3 *) vector_getp(state->geom, i0);
145             Plane  *plane = (Plane *) vector_getp(state->geom, i1);
146 
147             (void) extend_line_to_plane(&line->p1, &line->p2, dirn,
148                                         plane->p, plane->n);
149             break;
150         }
151     }
152 }
153 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.