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
|
2. rotation about the Y axis angle β
Formula:
x′=cosβ⋅x+sinβ⋅z
y′=y
z '= - + sinβ⋅x cosβ⋅
Finally, the code represents the
|
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
|
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
计算时照着公式代入即可。
最后给出代码实现:
|