Skip to content

Commit

Permalink
Merge pull request #26 from tinkerfuroc/vision_doc
Browse files Browse the repository at this point in the history
quaternion from vector
  • Loading branch information
cdsfcesf authored Jul 9, 2024
2 parents 38988f5 + 46ac451 commit 4945266
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/Documentation/Vision/cheat_sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,40 @@ Get quaternion from euler angles. Copied from ROS2 wiki.
</TabItem>

</Tabs>

### Quaternion from Vector

Get quaternion from a vector.

<Tabs>
<TabItem value="python" label="Python" default>

```python
import tf_transformations

rotation = np.eye(4)
# (x0, y0, z0) ------> (x1, y1, z1)
# x, y, z = x1 - x0, y1 - y0, z1 - z0
x, y, z = x0 - x1, y0 - y1, z0 - z1 # I don't know why but this one works

# x-axis
rotation[:3, 0] = np.array([x, y, z])
# z-axis, must be (0, 0, 1) when z == 0
rotation[:3, 2] = np.array([-x * z, - y * z, x ** 2 + y ** 2])
# y-axis, calculated from x and z
rotation[:3, 1] = np.array([y, -x, 0])
q = tf_transformations.quaternion_from_matrix(rotation)
```

</TabItem>

<TabItem value="c++" label="C++">

```c++
GUGUGU
```

</TabItem>

</Tabs>

0 comments on commit 4945266

Please sign in to comment.