ini
[aversive.git] / modules / base / math / vect2 / vect2.h
1 /*  
2  *  Copyright Droids Corporation, Microb Technology, Eirbot (2005)
3  * 
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.
8  *
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.
13  *
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
17  *
18  *  Revision : $Id: vect2.h,v 1.3.4.1 2006-11-26 21:06:01 zer0 Exp $
19  *
20  */
21
22 /** \file vect2.h
23 * \brief Interface for the 2 dimensional vector module.
24 * \author JD & Vincent
25 * \version 2.0
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.
29 *
30 * This module provides functions to handle 2d vectors and basic geometry fucntions.
31 */
32
33 /** \dontinclude main.c */
34
35 #ifndef _VECT2_H_
36 #define _VECT2_H_
37
38 /** \brief Definition of reals used in vector 2d */
39 typedef double Real;
40
41 #define TO_RAD(x) (((double)x)*(M_PI/180.0))
42 #define TO_DEG(x) (((double)x)*(180.0/M_PI))
43
44 /** \brief Cartesian vector structure
45 **/
46 typedef struct _vect2_cart
47 {
48    Real x;
49    Real y;
50    
51 }vect2_cart;
52
53
54 /** \brief Polar vector structure
55 **/
56 typedef struct _vect2_pol
57 {
58    Real r;
59    Real theta;
60    
61 }vect2_pol;
62
63 /************************ Begin prototyping ************************/
64
65 /** \addtogroup Convertions
66  * This functions allow to convert between the 2 vector types.
67  * @{
68  */
69
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.
74 *
75 **/
76 void vect2_pol2cart(vect2_pol* vp, vect2_cart* vc);
77
78
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.
83 *
84 **/
85 void vect2_cart2pol(vect2_cart* vc, vect2_pol* vp);
86
87 /** @} */
88
89
90 /** \addtogroup Basics
91  * This functions allow basic vector operations.
92  * @{
93  */
94
95
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.
103 *
104 * \f[ \vec V_{result} = \vec V_1 + \vec V_2 \f]
105 **/
106 void vect2_add_pol(vect2_pol* v1, vect2_pol* v2, vect2_pol* vresult);
107
108
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.
114 *
115 * \f[ \vec V_{result} = \vec V_1 + \vec V_2 \f]
116 **/
117 void vect2_add_cart(vect2_cart* v1, vect2_cart* v2, vect2_cart* vresult);
118
119
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.
129 *
130 * \f[ \vec V_{result} = \vec V_1 - \vec V_2 \f]
131 **/
132 void vect2_sub_pol(vect2_pol* v1, vect2_pol* v2, vect2_pol* vresult);
133
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.
139
140 * \f[ \vec V_{result} = \vec V_1 - \vec V_2 \f]
141 **/
142 void vect2_sub_cart(vect2_cart* v1, vect2_cart* v2, vect2_cart* vresult);
143
144
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.
150 *
151 * \f[ \vec V_{result} = \alpha\vec V_1 \f]
152 **/
153 void vect2_scale_cart(vect2_cart* v1, Real alpha, vect2_cart* vresult);
154
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.
160 *
161 * \f[ \vec V_{result} = \alpha\vec V_1 \f]
162 **/
163 void vect2_scale_pol(vect2_pol* v1, Real alpha, vect2_pol* vresult);
164
165 /** @} */
166
167
168 #endif /*_VECT2_H_*/