2 * Copyright Droids Corporation (2009)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $
24 #include <vect_base.h>
26 /* Return scalar product */
28 vect_pscal(vect_t *v, vect_t *w)
30 return v->x * w->x + v->y * w->y;
33 /* Return Z of vectorial product */
35 vect_pvect(vect_t *v, vect_t *w)
37 return v->x*w->y - v->y*w->x;
40 /* Return scalar product */
42 vect_pscal_sign(vect_t *v, vect_t *w)
51 /* Return Z of vectorial product */
53 vect_pvect_sign(vect_t *v, vect_t *w)
62 float xy_norm(float x1, float y1, float x2, float y2)
66 return sqrt(x*x + y*y);
69 float pt_norm(const point_t *p1, const point_t *p2)
71 float x = p2->x - p1->x;
72 float y = p2->y - p1->y;
73 return sqrt(x*x + y*y);
76 /* norm of a vector */
77 float vect_norm(const vect_t *v)
79 return sqrt(v->x*v->x+v->y*v->y);
82 void vect_rot_trigo(vect_t *v)
91 void vect_rot_retro(vect_t *v)
101 float vect_get_angle(vect_t *v, vect_t *w)
106 ps = vect_pscal(v, w);
107 n = vect_norm(v) * vect_norm(w);
109 return acos((float)ps/n);
112 void vect_resize(vect_t *v, float l)
114 float old_l = vect_norm(v);
115 float x = v->x, y = v->y;
116 v->x = x * l / old_l;
117 v->y = y * l / old_l;