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

Linux Cross Reference
Tina4/src/vision/line3/line3.c

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

  1 /**@(#)
  2 **/
  3 /* line3.c functions for manipulating 3D lines
  4  * 
  5  * typedef struct line3 { int type; struct vec3 p1,p2; struct vec3 v;
  6  * float length; struct list *props; } Line3;
  7  * 
  8  */
  9 
 10 #include <tina/sys.h>
 11 #include <tina/sysfuncs.h>
 12 #include <tina/math.h>
 13 #include <tina/mathfuncs.h>
 14 #include <tina/vision.h>
 15 #include <tina/visionfuncs.h>
 16 #ifdef _PCC
 17 #include <memory.h>
 18 #endif
 19 
 20 Line3  *line3_alloc(unsigned int type)
 21 {
 22     Line3  *line = ts_ralloc(Line3);
 23 
 24     line->type = type;
 25     line->label = new_label();
 26     return (line);
 27 }
 28 
 29 Line3  *line3_make(Vec3 p1, Vec3 p2, int type)
 30 {
 31     Line3  *line = ts_ralloc(Line3);
 32 
 33     line->type = type;
 34     line->label = new_label();
 35     line->p1 = p1;
 36     line->p2 = p2;
 37     line->p = vec3_times(0.5, vec3_sum(p1, p2));
 38     line->v = vec3_diff(p2, p1);
 39     line->length = (float)vec3_mod(line->v);
 40     line->v = vec3_times(1.0 / line->length, line->v);
 41     line->props = NULL;
 42     return (line);
 43 }
 44 
 45 void    line3_remake(Line3 * line, int type)
 46 {
 47     if (line == NULL)
 48         return;
 49 
 50     line->type = type;
 51     line->p = vec3_times(0.5, vec3_sum(line->p1, line->p2));
 52     line->v = vec3_diff(line->p2, line->p1);
 53     line->length = (float)vec3_mod(line->v);
 54     line->v = vec3_times(1.0 / line->length, line->v);
 55 }
 56 
 57 void    line3_free(Line3 * line)
 58 {
 59     if (line == NULL)
 60         return;
 61     proplist_freelist(line->props);
 62     rfree((void *) line);
 63 }
 64 
 65 Line3  *line3_copy(Line3 * line)/* identical copy that shares proplist */
 66 
 67 {
 68     Line3  *copy;
 69     List   *proplist_copy();
 70 
 71     if (line == NULL)
 72         return (NULL);
 73 
 74     copy = ts_ralloc(Line3);
 75     (void) memcpy((char *) copy, (char *) line, sizeof(Line3));
 76     copy->props = proplist_copy(line->props);
 77     return (copy);
 78 }
 79 
 80 Line3  *line3_clone(Line3 * line)       /* identical copy with null
 81                                          * proplist */
 82 
 83 {
 84     Line3  *copy;
 85 
 86     if (line == NULL)
 87         return (NULL);
 88 
 89     copy = ts_ralloc(Line3);
 90     (void) memcpy((char *) copy, (char *) line, sizeof(Line3));
 91     copy->props = NULL;
 92     return (copy);
 93 }
 94 
 95 Line3  *line3_negative(Line3 * line)
 96 {
 97     if (line == NULL)
 98         return (NULL);
 99 
100     line = line3_copy(line);
101     SWAP(Vec3, line->p1, line->p2);
102     line->v = vec3_minus(line->v);
103     return (line);
104 }
105 
106 void    line3_negate(Line3 * line)
107 {
108     if (line == NULL)
109         return;
110 
111     SWAP(Vec3, line->p1, line->p2);
112     line->v = vec3_minus(line->v);
113 }
114 
115 /* rough separation between mid points */
116 
117 double  line3_separation(Line3 * l1, Line3 * l2)
118 {
119     Vec3    c1 = {Vec3_id};
120     Vec3    c2 = {Vec3_id};
121 
122     if (l1 == NULL || l2 == NULL)
123         return (0.0);           /* meaningless */
124 
125     c1 = vec3_times(0.5, vec3_sum(l1->p1, l1->p2));
126     c2 = vec3_times(0.5, vec3_sum(l2->p1, l2->p2));
127 
128     return (vec3_mod(vec3_diff(c1, c2)));
129 }
130 
131 /* minimum separation between extended lines */
132 
133 double  line3_min_separation(Line3 * l1, Line3 * l2)
134 {
135     float   d1, d2, d3, d4;
136 
137     d1 = (float)vec3_mod(vec3_diff(l1->p1, l2->p1));
138     d2 = (float)vec3_mod(vec3_diff(l1->p1, l2->p2));
139     d3 = (float)vec3_mod(vec3_diff(l1->p2, l2->p1));
140     d4 = (float)vec3_mod(vec3_diff(l1->p2, l2->p2));
141 
142     d1 = MIN(d1, d2);
143     d3 = MIN(d3, d4);
144 
145     return (MIN(d1, d3));
146 }
147 
148 Vec3    vec3_along_line(Line3 *line, double frac)
149 {
150     Vec3 d = {Vec3_id};
151     
152     d = vec3_times(frac*line->length,line->v);
153     d = vec3_sum(line->p1, d);
154         
155     return(d); 
156 }
157 
158 Bool    line3_point_on_line(Line3 * line, Vec3 p, double thres)
159 {
160     Vec3    d = {Vec3_id};
161     double  dp;
162 
163     d = vec3_diff(p, line->p1);
164     dp = vec3_dot(line->v, d);
165     d = vec3_diff(d, vec3_times(dp, line->v));
166     return ((vec3_sqrmod(d) < SQR(thres)) ? true : false);
167 }
168 

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