How do I do a coordinate transformation (cartesian to polar) in a double integral using sympy? For example, from:
Integral(exp(-x**2-y**2), (x,-oo,oo), (y,-oo,oo))
To:
Integral(exp(-r**2)*r, (r,0,oo), (t,0,2*pi))
Related
What I am trying to do is convert two points in spherical coordinates to geographic coordinates, in order to them make use of the vincenty distance function, in order to accurately measure the distance between the two points on a unit sphere.
The following code fails to transform a pair of spherical points to a pairs of geographic ones, returning inf values for the elements in p1_g and p2_g.
Any suggestion of what I am doing wrong is much appreciated.
VectorXd p1(2) ;
VectorXd p2(2) ;
p1 << -2.35619, 0.955317 ;
p2 << 1.47275, 2.53697 ;
namespace bg = boost::geometry;
typedef boost::geometry::srs::spheroid<double> SpheroidType;
SpheroidType spheriod(1.0,1.0);
typedef boost::geometry::strategy::distance::vincenty<SpheroidType>
VincentyStrategy;
VincentyStrategy vincenty(spheriod);
bg::model::point<double, 2, bg::cs::spherical<bg::radian>> p1_s(p1(0), p1(1));
bg::model::point<double, 2, bg::cs::spherical<bg::radian>> p2_s(p2(0), p2(1));
bg::model::point<double, 2, bg::cs::geographic<bg::radian> > p1_g;
bg::model::point<double, 2, bg::cs::geographic<bg::radian> > p2_g;
bg::transform(p1_s, p1_g, vincenty);
bg::transform(p2_s, p2_g, vincenty);
auto dist = bg::distance(p1_g, p2_g, vincenty);
You appear to be confused about spheres and spheroids.
A sphere is effectively a perfectly round ball. While a spheroid is a sphere that has been squashed (or extended) along an axis, see: https://en.wikipedia.org/wiki/Spheroid.
Another name for spheroid is ellipsoid. The best known spheroid is the WGS-84 spheroid used by GPS systems.
Distances between points on a sphere can be calculated relatively simply using the haversine equation, while distances between points on a spheroid require complicated equations such as Vincenty's or (the more accurate) Karney's equations.
To calculate distances on a unit sphere, simply use the boost haversine strategy and then multiply by the radius to convert the distance from radians to your desired units. The non-Cartesian distance example here shows it being performed with coordinates in degrees.
I'm working on a OSG model which contains several DOFTransform nodes. In order to perform geometric calculations on the 3D model I need to know which are the axis of rotation and the point where this axis is placed, is that possible?
osgSim::DOFTransform
http://trac.openscenegraph.org/documentation/OpenSceneGraphReferenceDocs/a00215.html
has
const osg::Vec3& osgSim::DOFTransform::getCurrentHPR() const;
to get the Euler angles for **H**eading, **P**itch and **R**oll,and
MultOrder osgSim::DOFTransform::getHPRMultOrder() const;
to get the convention intended to be used for the sequence of rotations.
The reference point can be determined by
const osg::Vec3& osgSim::DOFTransform::getCurrentTranslate () const;
Given a vector v expressed in coordinates of the frame which the translation t refers to, it's
v' = v - t
on which the rotations are to be applied.
For conversion of an Euler angle to an axis/angle representation pls. attend:
https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Conversion_formulae_between_formalisms
In addition:
Let M be the combined rotation matrix, e.g.
M = H * P * R
(H,P,R here denoting the respective Matrices for the given angles) and vectors v', v'' with
v'' = M * v'
which are not collinear, the axis searched for is simply their normalized cross product, and the angle can be found by applying basic trigonometry.
Using the mathematics library GLM, I use this code to combine the euler angle rotations to a rotation matrix.
#include <GLM/gtc/matrix_transform.hpp>
using namespace glm;
mat4 matrix = rotate(mat4(1), X, vec3(1, 0, 0))
* rotate(mat4(1), Y, vec3(0, 1, 0))
* rotate(mat4(1), Z, vec3(0, 0, 1));
Does this result in an euler angle sequenze of XYZ or ZYX? I am not sure since matrix multiplication behave not the same as scalar multiplications.
Remember that matrix calculation, in openGL, use a notation knows as vector column (http://en.wikipedia.org/wiki/Column_vector). So, any point transformation will be expressed by a system of linear equation, expressed in vector column notation like this:
[P'] = M.[P], where M = M1.M2.M3
This means that the first transformation that is applied to the points, expressed by vector [P] is M3, after that by M2 and at last by M1.
Answering your question, the resulting Euler angle will be ZXY, once Z rotation transformation is the last matrix that you write to form a matrix multiplication.
I have a chessboard in two images with some angle of rotation. Lets find the rotation angle of second image with reference of first image.
For that I found the Rotation Matrix (3x3) and translation matrix (3x1) of those objects.
How can I find the Rotation Angle and Rotation Axis of object using those matrices?
For every type of conversion between rotation representations you have this website euclidean space.
You will find theory and code samples of:
Rotation matrix to quaternion: link
Quaternion to axis angle: link
Rotations in general and all representations: link
And in relation to your question you have Axis Angle. If you have the rotation matrix R (3x3), you can obtain the angle and axis this way (see Matrix to Axis Angle):
angle = acos(( R00 + R11 + R22 - 1)/2);
Axis x,y,x:
x = (R21 - R12)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);
y = (R02 - R20)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);
z = (R10 - R01)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);
Already working wih openCV I would rcommend using the Rodrigues method:
cv::Rodrigues(src, dst, jacobian), that computes the rotation vector if you have a rotation matrix for an argument and vice versa.
How can I rotate the point (x, y, z) by angles (rx, ry, rz) about their respective axes?
That is, how do I determine the point (x1, y1, z1) resulting from the rotation of (x, y, z) by rotation angles (rx, ry, rz)?
Are there any DirectX routines which accomplish this?
What you are asking about is how to use Euler Angles for performing rotations. There are several conventions you can choose from, but it looks to me like you are interested in applying rotation about the Z axis, followed by rotation about Y and then rotation about X. For this you would post multiply by the matrix
where
c1 = cos(rx) s1 = sin(rx)
c2 = cos(ry) s2 = sin(ry)
cs = cos(rz) s3 = sin(rz)
There are several problems with this approach, one of the more common being gimbal lock. The preferred approach is to use one of the angle-axis formulations. The two most common of those are Unit Quaternion Rotations and Euler-Rodreigues Rotation Matrices. These can be composed to generate any of the 12 Euler Rotation matrices by explicitly defining three rotation axes and their associated rotation angles and then multiplying the resulting rotation representation in the reverse order they are to be applied to the vectors to be rotated.
DirectX uses Quaternions for performing rotations.
During my electronics(EM) classes I learnt converting cartesian to polar cordinates using the formula
x = r sinq cosf, y = r sinq sinf, z = r cosq
More Info Here
q is theta, f is phi.