Skip to content

Commit

Permalink
added section about xy array class
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiye Shizhi committed Jan 15, 2025
1 parent 2ecee2f commit d8fcc8e
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion doc/2_vehicle_model/2_vehicle_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,56 @@ Implementing a member method of State class, "draw" for visualization. In this c
elems.append(hist_plot)

elems.append(axes.text(self.x_m, self.y_m + 2, "Speed: " + str(round(self.speed_mps * 3.6, 1)) + "[km/h]", fontsize=10))
```
```

### 2.4.2 X-Y Array class
The vehicle's drawing is represented as x-y 2D array. So, I implement X-Y Array class as follow.
[xy_array.py](/src/components/array/xy_array.py)

```python
"""
xy_array.py
Author: Shisato Yano
"""

from math import sin, cos
import numpy as np


class XYArray:
"""
X-Y 2D array data and logic class
"""

def __init__(self, data):
"""
Constructor
data: np.array([[x1, x2,..., xn], [y1, y2,..., yn]])
"""

self.data = data

def homogeneous_transformation(self, x, y, angle_rad):
"""
Function for homogeneous transformation
x: Amount of x-axis translation
y: Amount of y-axis translation
angle_rad: Rotation angle[rad]
Return transformed XYArray object
"""

angle_cos = cos(angle_rad)
angle_sin = sin(angle_rad)

rotation_matrix = np.array([[angle_cos, -angle_sin],
[angle_sin, angle_cos]])

rotated_data = rotation_matrix @ self.data

translated_data = rotated_data + np.ones(rotated_data.shape) * np.array([[x], [y]])

return XYArray(translated_data)
```

In this code, a given data to Constructor is x-y 2D array. Then, the data can be transformed based on the vehicle's position (x, y) and yaw angle. After the data was transformed, a new XYArray object with the transformed data is returned.

0 comments on commit d8fcc8e

Please sign in to comment.