This forum has been archived. All content is frozen. Please use KDE Discuss instead.

inverse trigonometric functions???

Tags: None
(comma "," separated)
Blines
Registered Member
Posts
2
Karma
0
OS

inverse trigonometric functions???

Sun Mar 14, 2010 5:13 pm
I'm sorry, I am new to c++. I try to use from the beginning the Eigen Bib and I have to use a arcsin and arccos function to a MatrixXd.

How can I do that?

Thanks
User avatar
bjacob
Registered Member
Posts
658
Karma
3
We don't provide a built-in function for that, but we provide a way to apply any function to a matrix, you just have to wrap that function into a "functor' object, see:
http://eigen.tuxfamily.org/dox/classEig ... 045c8a2e9e


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
Blines
Registered Member
Posts
2
Karma
0
OS
Thanks a lot bjacob, for your response and for sharing this very ambitous project.
I managed to get this working by learning and stealing from more experienced users ;). I'll post the code for all the other c++ newbies which are confronted with the same basic problems then me.

1. In the main.h I added the following lines:
Code: Select all
#define EIGEN_CWISE_PLUGIN "CwiseAddons.h"
#define EIGEN_FUNCTORS_PLUGIN "FunctorsAddons.h"

#include <Eigen/Core>
#include <Eigen/Array>
#include <Eigen/Geometry>


2. In the FunctorsAddons.h it's:
Code: Select all
#ifndef FUNCTORSADDONS_H
#define FUNCTORSADDONS_H

/* ++++++ asin() ++++++ */
template<typename Scalar> struct ei_scalar_asin_op EIGEN_EMPTY_STRUCT {
  inline const Scalar operator() (const Scalar& a) const { return std::asin(a); }
};

template<typename Scalar>
struct ei_functor_traits<ei_scalar_asin_op<Scalar> >
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };

/* ++++++ acos() ++++++ */
template<typename Scalar> struct ei_scalar_acos_op EIGEN_EMPTY_STRUCT {
  inline const Scalar operator() (const Scalar& a) const { return std::acos(a); }
};

template<typename Scalar>
struct ei_functor_traits<ei_scalar_acos_op<Scalar> >
{ enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false }; };

#endif // FUNCTORSADDONS_H



Feel free to add more functions from the std bib.

3. In the CwiseAddons.h it's:
Code: Select all
#ifndef CWISEADDONS_H
#define CWISEADDONS_H

inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_asin_op)
asin() const
{
  return _expression();
}

inline const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_acos_op)
acos() const
{
  return _expression();
}

#endif // CWISEADDONS_H


One can call these functions then in the main.cpp by:
Code: Select all
m2 = m1.cwise().acos();


Hf!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Excellent, I'll be pointing people to your tutorial. Thanks for sharing it!


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan, sandyvee