Filter löschen
Filter löschen

Plot of Euler Angles and Temperature changing with time

6 Ansichten (letzte 30 Tage)
Claudia George
Claudia George am 5 Nov. 2021
Beantwortet: Nirupama am 27 Feb. 2024
I have Euler Angles (roll, pitch and yaw) of a sensor and temperature measured by the sensor at each of the Euler angles point in space.
For example, (180.82 roll, -1.65 pitch, 2.48 yaw, 25 degC, 5 seconds) and (180 roll, -1.7 pitch, 2.0 yaw, 25.5 degC, 10 seconds) etc.
I want to be able to plot the temperature at each 3D point in space changing with time. I am wondering which MATLAB function to use?
A reply will be much appreciated.
Thank you.

Antworten (1)

Nirupama
Nirupama am 27 Feb. 2024
From the description that you have provided, I believe you would like to plot the temperature measured by a sensor in 3D space that changes with time.
You have the Euler angle representation of the sensor which describes the orientation of the sensor in space rather than positions.
You can follow the steps mentioned below:
  1. Convert Euler angles to a direction vector: Use the roll, pitch, and yaw angles to create a direction vector in 3D space. You can assume a fixed radius if you are treating the angles as spherical coordinates.
  2. Map the direction vector to a temperature: Based on the direction vector and temperature data, create a mapping that allows you to plot temperature values in 3D space.
  3. Plot the data: Make use MATLAB functions like "scatter3" or "plot3" to plot the points in a 3D space.
  4. Animate the plot: Update the plot in a loop to show how temperature changes over time.
You can refer to the sample MATLAB code below:
% Define a fixed radius if necessary
radius = 1; %all points are at a unit distance from the origin
% Example data (roll, pitch, yaw, temperature, time)
data = [
180.82, -1.65, 2.48, 25, 5;
180, -1.7, 2.0, 25.5, 10
% ... add more data points here
];
% Initialize the figure
figure;
h = scatter3([], [], [], [], 'filled');
xlabel('X');
ylabel('Y');
zlabel('Z');
c = colorbar;
c.Label.String = 'Temperature (°C)';
title('Temperature at Sensor Location Over Time');
% Loop through the data points
for i = 1:size(data, 1)
% Extract the Euler angles and temperature
roll = data(i, 1);
pitch = data(i, 2);
yaw = data(i, 3);
temp = data(i, 4);
% Convert angles to radians
roll_rad = deg2rad(roll);
pitch_rad = deg2rad(pitch);
yaw_rad = deg2rad(yaw);
% Convert Euler angles to Cartesian coordinates (assuming roll is rotation around Z)
x = radius * cos(yaw_rad) * cos(pitch_rad);
y = radius * sin(yaw_rad) * cos(pitch_rad);
z = radius * sin(pitch_rad); % Assuming pitch is rotation around Y
% Update the scatter plot
set(h, 'XData', x, 'YData', y, 'ZData', z, 'CData', temp, 'SizeData', 100);
drawnow;
% Pause to simulate time passing
pause(data(i, 5)); % Using the time column to pause
end
The "scatter3" function is used to plot the temperature data in 3D space, with the color indicating the temperature. The "pause" function uses the time data to simulate the time passing between measurements.
Please note that this approach I have assumed that each set of Euler angles (roll, pitch, yaw) corresponds to a unique point in space. If the sensor moves in space and changes orientation, then you would need to incorporate its trajectory into the position calculation, which complicates the process significantly.
You can refer to the following MATLAB documentation links for more details:
Hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by