The inner layer to the outer layer in terms of displacement

The inner layer to the outer layer in terms of displacement

 

In the realization of three-dimensional features in the scene, there is need to make use of UG in the coordinate system is rotated and functions similar to the translation node, implemented in the discovery process,

If the translation layer is positioned within the rotation of the functional layer, then: rotation, translation if the prior operation has elapsed, the node will cause swinging in the scene, moving without rotating center;

If the level-shifting layer is disposed outside the rotation of the functional layer, then: when translated, if advance by the rotation, to cause the node in the scene coordinate axis translation Africa, rather than the original direction of translation of the sensor.

After reflection, the following programs: a rotation of each inner and outer rotating layer in the translation layer, the inner layer in each pan (guaranteed by the coordinate axis translation) After completion of the inner layer data translation, conversion to the outer layer, inner layer and then reset data to the state at the start of translation, in order to ensure that the relative position of nodes inner world coordinate system unchanged, and does not affect the rotation (not to generate swinging phenomenon) and the next translation.

The following is a correlation algorithm.

First, rotation algorithms

One problem: a point XYZ space around the X, Y, Z axis once

This problem is relatively simple, the Internet has been more summary:

Coordinates before rotation is provided , the rotation coordinates .

 1. The angle γ around the Z axis

Formula:

x′=cosγ⋅x−sinγ⋅y

y '= sinγ⋅x + coγ⋅y

z′=z

Finally, the code represents the

 

//将空间点绕Z轴旋转

//输入参数 x y为空间点原始x y坐标

//thetaz为空间点绕Z轴旋转多少度,角度制范围在-180到180

//outx outy为旋转后的结果坐标

void codeRotateByZ(double x, double y, double thetaz, double& outx, double& outy)

{

    double x1 = x;//将变量拷贝一次,保证&x == &outx这种情况下也能计算正确

    double y1 = y;

    double rz = thetaz * CV_PI / 180;

    outx = cos(rz) * x1 - sin(rz) * y1;

    outy = sin(rz) * x1 + cos(rz) * y1;

 

}

 

2. rotation about the Y axis angle β

Formula:

x′=cosβ⋅x+sinβ⋅z

y′=y

z '= - + sinβ⋅x cosβ⋅

 

Finally, the code represents the

//将空间点绕Y轴旋转

//输入参数 x z为空间点原始x z坐标

//thetay为空间点绕Y轴旋转多少度,角度制范围在-180到180

//outx outz为旋转后的结果坐标

void codeRotateByY(double x, double z, double thetay, double& outx, double& outz)

{

    double x1 = x;

    double z1 = z;

    double ry = thetay * CV_PI / 180;

    outx = cos(ry) * x1 + sin(ry) * z1;

    outz = cos(ry) * z1 - sin(ry) * x1;

}

   

3. The angle of rotation α about the axis X

Formula:

x′=x

y '= cosα⋅y-sinα⋅z

z '= sinα⋅y + sinα⋅z

Finally, the code represents the

//将空间点绕X轴旋转

//输入参数 y z为空间点原始y z坐标

//thetax为空间点绕X轴旋转多少度,角度制范围在-180到180

//outy outz为旋转后的结果坐标

void codeRotateByX(double y, double z, double thetax, double& outy, double& outz)

{

    double y1 = y;//将变量拷贝一次,保证&y == &y这种情况下也能计算正确

    double z1 = z;

    double rx = thetax * CV_PI / 180;

    outy = cos(rx) * y1 - sin(rx) * z1;

    outz = cos(rx) * z1 + sin(rx) * y1;

}

   

Second problem: arbitrary spatial point about the axis of rotation

First, the need to define "any axis" unit vector, for example, an X-axis vector can be expressed.

Then it is assumed for the rotational axis unit vector , rotating the former coordinates , the coordinates of rotation , angle of rotation , so there are:

 

x′=(vx⋅vx⋅(1−cosθ)+cosθ)⋅x+(vx⋅vy⋅(1−cosθ)−vz⋅sinθ)⋅y+(vx⋅vz⋅(1−cosθ)+vy⋅sinθ)⋅z

y′=(vx⋅vy⋅(1−cosθ)+vz⋅sinθ)⋅x+(vy⋅vy⋅(1−cosθ)+cosθ)⋅y+(vy⋅vz⋅(1−cosθ)−vx⋅sinθ)⋅z

z′=(vx⋅vz⋅(1−cosθ)−vy⋅sinθ)⋅x+(vy⋅vz⋅(1−cosθ)+vx⋅sinθ)⋅y+(vz⋅vz⋅(1−cosθ)+cosθ)⋅z

计算时照着公式代入即可。

最后给出代码实现:

 

//定义返回结构体

struct Point3f

{

    Point3f(double _x, double _y, double _z)

    {

        x = _x;

        y = _y;

        z = _z;

    }

    double x;

    double y;

    double z;

};

 

//点绕任意向量旋转,右手系

//输入参数old_x,old_y,old_z为旋转前空间点的坐标

//vx,vy,vz为旋转轴向量

//theta为旋转角度角度制,范围在-180到180

//返回值为旋转后坐标点

Point3f RotateByVector(double old_x, double old_y, double old_z, double vx, double vy, double vz, double theta)

{

    double r = theta * CV_PI / 180;

    double c = cos(r);

    double s = sin(r);

    double new_x = (vx*vx*(1 - c) + c) * old_x + (vx*vy*(1 - c) - vz*s) * old_y + (vx*vz*(1 - c) + vy*s) * old_z;

    double new_y = (vy*vx*(1 - c) + vz*s) * old_x + (vy*vy*(1 - c) + c) * old_y + (vy*vz*(1 - c) - vx*s) * old_z;

    double new_z = (vx*vz*(1 - c) - vy*s) * old_x + (vy*vz*(1 - c) + vx*s) * old_y + (vz*vz*(1 - c) + c) * old_z;

    return Point3f(new_x, new_y, new_z);

}

 

Guess you like

Origin www.cnblogs.com/ice-arrow/p/11164691.html