2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
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: vect2.h,v 1.3.4.1 2006-11-26 21:06:01 zer0 Exp $
23 * \brief Interface for the 2 dimensional vector module.
24 * \author JD & Vincent
26 * \date 21.12.2005 @ 23:09
27 * \todo Complex operations on vectors and implementation of the <french> reperes </french>
28 * \test polar -> cartesian & cartesian -> polar seems to be ok.
30 * This module provides functions to handle 2d vectors and basic geometry fucntions.
33 /** \dontinclude main.c */
38 /** \brief Definition of reals used in vector 2d */
41 #define TO_RAD(x) (((double)x)*(M_PI/180.0))
42 #define TO_DEG(x) (((double)x)*(180.0/M_PI))
44 /** \brief Cartesian vector structure
46 typedef struct _vect2_cart
54 /** \brief Polar vector structure
56 typedef struct _vect2_pol
63 /************************ Begin prototyping ************************/
65 /** \addtogroup Convertions
66 * This functions allow to convert between the 2 vector types.
70 /** \brief Convert a polar vector to a cartesian one
71 * \param vp reference to target polar vector to convert from.
72 * \param vc reference to target cartesian vector where the function write.
73 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
76 void vect2_pol2cart(vect2_pol* vp, vect2_cart* vc);
79 /** \brief Convert a cartesian vector to a polar one
80 * \param vc reference to target cartesian vector to convert from.
81 * \param vp reference to target polar vector where the function write the result.
82 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
85 void vect2_cart2pol(vect2_cart* vc, vect2_pol* vp);
90 /** \addtogroup Basics
91 * This functions allow basic vector operations.
96 /** \brief Add 2 polar vectors and return the result
97 * \param v1 Reference to a polar vector to sum.
98 * \param v2 Reference to a polar vector to sum.
99 * \param vresult Reference to a polar vector to store the result.
100 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
101 * \note This function convert the 2 entry vectors to cartesian, sum them and then convert the result to polar.
102 * So please think before using it.
104 * \f[ \vec V_{result} = \vec V_1 + \vec V_2 \f]
106 void vect2_add_pol(vect2_pol* v1, vect2_pol* v2, vect2_pol* vresult);
109 /** \brief Add 2 cartesian vectors and return the result
110 * \param v1 Reference to a cartesian vector to sum.
111 * \param v2 Reference to a cartesian vector to sum.
112 * \param vresult Reference to a polar vector to store the result.
113 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
115 * \f[ \vec V_{result} = \vec V_1 + \vec V_2 \f]
117 void vect2_add_cart(vect2_cart* v1, vect2_cart* v2, vect2_cart* vresult);
120 /** \brief Substract 2 polar vectors and return the result
121 * \param v1 Reference to a polar vector to substract.
122 * \param v2 Reference to a polar vector to substract.
123 * \param vresult Reference to a polar vector to store the result.
124 * \warning This function doesn't do any
125 Real R = 1.45064930529587234;
126 Real theta = 0.6734390282904231341;malloc ! You have to allocate structures before calling this function.
127 * \note This function convert the 2 entry vectors to cartesian, substract them and then convert the result to polar.
128 * So please think before using it.
130 * \f[ \vec V_{result} = \vec V_1 - \vec V_2 \f]
132 void vect2_sub_pol(vect2_pol* v1, vect2_pol* v2, vect2_pol* vresult);
134 /** \brief Substract 2 cartesian vectors and return the result
135 * \param v1 Reference to a cartesian vector to substract.
136 * \param v2 Reference to a cartesian vector to substract.
137 * \param vresult Reference to a cartesian vector to store the result.
138 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
140 * \f[ \vec V_{result} = \vec V_1 - \vec V_2 \f]
142 void vect2_sub_cart(vect2_cart* v1, vect2_cart* v2, vect2_cart* vresult);
145 /** \brief Multiply a cartesian vector by a scalar and return the result
146 * \param v1 Reference to a cartesian vector.
147 * \param alpha The multiplying scalar.
148 * \param vresult Reference to a cartesian vector to store the result.
149 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
151 * \f[ \vec V_{result} = \alpha\vec V_1 \f]
153 void vect2_scale_cart(vect2_cart* v1, Real alpha, vect2_cart* vresult);
155 /** \brief Multiply a polar vector by a scalar and return the result
156 * \param v1 Reference to a polar vector.
157 * \param alpha The multiplying scalar.
158 * \param vresult Reference to a cartesian vector to store the result.
159 * \warning This function doesn't do any malloc ! You have to allocate structures before calling this function.
161 * \f[ \vec V_{result} = \alpha\vec V_1 \f]
163 void vect2_scale_pol(vect2_pol* v1, Real alpha, vect2_pol* vresult);