X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=modules%2Fbase%2Fmath%2Fgeometry%2Fvect_base.c;h=9ea271dc81461677cb332dc0c0a0e75fb91aeed4;hp=f36724c40601410f8c32608f50cd4c9dad2c2707;hb=a875ac1ccbff0fa41013996ec6d50d4b78f53d01;hpb=ccc6954bb046671b9e28c5806db5121c1eef49c0 diff --git a/modules/base/math/geometry/vect_base.c b/modules/base/math/geometry/vect_base.c index f36724c..9ea271d 100755 --- a/modules/base/math/geometry/vect_base.c +++ b/modules/base/math/geometry/vect_base.c @@ -1,16 +1,37 @@ +/* + * Copyright Droids Corporation (2009) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $ + * + */ + #include #include #include /* Return scalar product */ -int32_t +float vect_pscal(vect_t *v, vect_t *w) { return v->x * w->x + v->y * w->y; } /* Return Z of vectorial product */ -int32_t +float vect_pvect(vect_t *v, vect_t *w) { return v->x*w->y - v->y*w->x; @@ -20,7 +41,7 @@ vect_pvect(vect_t *v, vect_t *w) int8_t vect_pscal_sign(vect_t *v, vect_t *w) { - int32_t z; + float z; z = vect_pscal(v, w); if (z==0) return 0; @@ -31,13 +52,27 @@ vect_pscal_sign(vect_t *v, vect_t *w) int8_t vect_pvect_sign(vect_t *v, vect_t *w) { - int32_t z; + float z; z = vect_pvect(v, w); if (z==0) return 0; return z>0?1:-1; } +/* float norm(float x1, float y1, float x2, float y2) */ +/* { */ +/* float x = x2 - x1; */ +/* float y = y2 - y1; */ +/* return sqrt(x*x + y*y); */ +/* } */ + +float pt_norm(point_t *p1, point_t *p2) +{ + float x = p2->x - p1->x; + float y = p2->y - p1->y; + return sqrt(x*x + y*y); +} + /* norm of a vector */ float vect_norm(vect_t *v) @@ -45,11 +80,9 @@ vect_norm(vect_t *v) return sqrt(v->x*v->x+v->y*v->y); } - - void vect_rot_trigo(vect_t *v) { - int32_t s; + float s; s = v->x; v->x= -v->y; @@ -58,7 +91,7 @@ void vect_rot_trigo(vect_t *v) void vect_rot_retro(vect_t *v) { - int32_t s; + float s; s = v->x; v->x= v->y; @@ -68,7 +101,7 @@ void vect_rot_retro(vect_t *v) float vect_get_angle(vect_t *v, vect_t *w) { - int32_t ps; + float ps; float n; ps = vect_pscal(v, w); @@ -76,3 +109,11 @@ float vect_get_angle(vect_t *v, vect_t *w) return acos((float)ps/n); } + +void vect_resize(vect_t *v, float l) +{ + float old_l = vect_norm(v); + float x = v->x, y = v->y; + v->x = x * l / old_l; + v->y = y * l / old_l; +}