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

Linux Cross Reference
Tina4/src/geomstat/constraint/state_add.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 int     state_add_intersect(State * state, int i0, int i1)
 13 {
 14     int     inew;
 15     int     type0, type1;
 16 
 17     if (state_badpair(state, i0, i1))
 18         return (-1);
 19 
 20     type0 = vector_get(state->type, i0);
 21     type1 = vector_get(state->type, i1);
 22     (void) geom_reorder(&i0, &i1, &type0, &type1);
 23 
 24     switch (OPAIR(type0, type1))
 25     {
 26     case OPAIR(LINE3, LINE3):
 27         {
 28             Line3  *line0 = (Line3 *) vector_getp(state->geom, i0);
 29             Line3  *line1 = (Line3 *) vector_getp(state->geom, i1);
 30             Point3 *point;
 31             Vec3    p = {Vec3_id};
 32 
 33             p = vec3_inter_lines(line0->p, line0->v, line1->p, line1->v);
 34             point = point3_make(p, (int) NULL);
 35             inew = state_add(state, (void *) point, POINT3);
 36             state_set_infcov(state, inew);
 37             break;
 38         }
 39     case OPAIR(LINE3, PLANE):
 40         {
 41             Line3  *line = (Line3 *) vector_getp(state->geom, i0);
 42             Plane  *plane = (Plane *) vector_getp(state->geom, i1);
 43             Point3 *point;
 44             Vec3    p = {Vec3_id};
 45 
 46             p = vec3_inter_line_plane(line->p, line->v, plane->p, plane->n);
 47             point = point3_make(p, (int) NULL);
 48             inew = state_add(state, (void *) point, POINT3);
 49             state_set_infcov(state, inew);
 50             break;
 51         }
 52     case OPAIR(PLANE, PLANE):
 53         {
 54             Plane  *plane0 = (Plane *) vector_getp(state->geom, i0);
 55             Plane  *plane1 = (Plane *) vector_getp(state->geom, i1);
 56             Line3  *line;
 57             Vec3    l = {Vec3_id};
 58             Vec3    v = {Vec3_id};
 59             Vec3    p1 = {Vec3_id};
 60             Vec3    p2 = {Vec3_id};
 61 
 62             vec3_inter_planes(plane0->p, plane0->n, plane1->p, plane1->n, &l, &v);
 63             p1 = vec3_diff(l, vec3_times(state->lscale / 16.0, v));
 64             p2 = vec3_sum(l, vec3_times(state->lscale / 16.0, v));
 65             line = line3_make(p1, p2, (int) NULL);
 66             inew = state_add(state, (void *) line, LINE3);
 67             state_set_infcov(state, inew);
 68             break;
 69         }
 70     default:
 71         inew = -1;
 72     }
 73     return (inew);
 74 }
 75 
 76 int     state_add_join(State * state, int i0, int i1)
 77 {
 78     int     inew;
 79     int     type0, type1;
 80 
 81     if (state_badpair(state, i0, i1))
 82         return (-1);
 83 
 84     type0 = vector_get(state->type, i0);
 85     type1 = vector_get(state->type, i1);
 86     (void) geom_reorder(&i0, &i1, &type0, &type1);
 87 
 88     switch (OPAIR(type0, type1))
 89     {
 90     case OPAIR(POINT3, POINT3):
 91         {
 92             Point3 *point0 = (Point3 *) vector_getp(state->geom, i0);
 93             Point3 *point1 = (Point3 *) vector_getp(state->geom, i1);
 94             Line3  *line;
 95 
 96             line = line3_make(point0->p, point1->p, (int) NULL);
 97             inew = state_add(state, (void *) line, LINE3);
 98             state_set_infcov(state, inew);
 99             break;
100         }
101     case OPAIR(POINT3, LINE3):
102         {
103             Point3 *point = (Point3 *) vector_getp(state->geom, i0);
104             Line3  *line = (Line3 *) vector_getp(state->geom, i1);
105             Plane  *plane;
106             Vec3    p = {Vec3_id};
107             Vec3    n = {Vec3_id};
108 
109             vec3_join_point_line(point->p, line->p, line->v, &p, &n);
110             plane = plane_make(p, n, (int) NULL);
111             inew = state_add(state, (void *) plane, PLANE);
112             state_set_infcov(state, inew);
113             break;
114         }
115     case OPAIR(LINE3, LINE3):
116         {
117             Line3  *line0 = (Line3 *) vector_getp(state->geom, i0);
118             Line3  *line1 = (Line3 *) vector_getp(state->geom, i1);
119             Plane  *plane;
120             Vec3    p = {Vec3_id};
121             Vec3    n = {Vec3_id};
122 
123             vec3_join_lines(line0->p, line0->v, line1->p, line1->v, &p, &n);
124             plane = plane_make(p, n, (int) NULL);
125             inew = state_add(state, (void *) plane, PLANE);
126             state_set_infcov(state, inew);
127             break;
128         }
129     default:
130         inew = -1;
131     }
132     return (inew);
133 }
134 
135 int     state_add_join3(State * state, int i0, int i1, int i2)
136 {
137     int     inew;
138     int     type0, type1, type2;
139 
140 
141     type0 = vector_get(state->type, i0);
142     type1 = vector_get(state->type, i1);
143     type2 = vector_get(state->type, i2);
144     if ((i0 < 0 || i0 >= state->maxindex) ||
145         (i1 < 1 || i1 >= state->maxindex) ||
146         (i0 < 2 || i2 >= state->maxindex))
147     {
148         error("state_add_join3: bad index", non_fatal);
149         return (-1);
150     }
151     if (type0 != POINT3 || type1 != POINT3 || type2 != POINT3)
152     {
153         error("state_add_join3: bad types", non_fatal);
154         return (-1);
155     }
156     {
157         Point3 *point0 = (Point3 *) vector_getp(state->geom, i0);
158         Point3 *point1 = (Point3 *) vector_getp(state->geom, i1);
159         Point3 *point2 = (Point3 *) vector_getp(state->geom, i2);
160         Plane  *plane;
161         Vec3    p = {Vec3_id};
162         Vec3    n = {Vec3_id};
163 
164         vec3_join_3_points(point0->p, point1->p, point2->p, &p, &n);
165         plane = plane_make(p, n, (int) NULL);
166         inew = state_add(state, (void *) plane, PLANE);
167         state_set_infcov(state, inew);
168     }
169 
170     return (inew);
171 }
172 

~ [ 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.