coord.h

00001 
00002 /***************************************************************************
00003  *  coord.h - coordinate transformation and coord sys related functions
00004  *
00005  *  Created: Wed Jul 16 19:07:37 2008 (RoboCup 2008, Suzhou)
00006  *  Copyright  2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #ifndef __UTILS_MATH_COORD_H_
00025 #define __UTILS_MATH_COORD_H_
00026 
00027 #include <cmath>
00028 
00029 namespace fawkes {
00030 
00031 
00032 /** Convert a 2D polar coordinate to a 2D cartesian coordinate.
00033  * @param polar_phi Phi of the polar coordinate
00034  * @param polar_dist distnace of the polar coordinate
00035  * @param cart_x upon return contains X of the cartesian coordinate
00036  * @param cart_y upon return contains Y of the cartesian coordinate
00037  */
00038 inline void
00039 cart2polar2d(float cart_x, float cart_y,
00040              float *polar_phi, float *polar_dist)
00041 {
00042   *polar_phi  = atan2f(cart_y, cart_x);
00043   *polar_dist = sqrtf(cart_x * cart_x + cart_y * cart_y);
00044 }
00045 
00046 
00047 /** Convert a 2D polar coordinate to a 2D cartesian coordinate.
00048  * @param polar_phi Phi of the polar coordinate
00049  * @param polar_dist distnace of the polar coordinate
00050  * @param cart_x upon return contains X of the cartesian coordinate
00051  * @param cart_y upon return contains Y of the cartesian coordinate
00052  */
00053 inline void
00054 polar2cart2d(float polar_phi, float polar_dist,
00055              float *cart_x, float *cart_y)
00056 {
00057   *cart_x = polar_dist * cosf(polar_phi);
00058   *cart_y = polar_dist * sinf(polar_phi);
00059 }
00060 
00061 
00062 } // end namespace fawkes
00063 
00064 #endif