-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrotmy.m
50 lines (42 loc) · 1.18 KB
/
rotmy.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%ROTMY Create SO(3) matrix for rotation about Y axis
%
% R = ROTMY(THETA) is an SO(3) rotation matrix (3x3) representing a
% rotation of THETA radians about the y-axis.
%
% R = ROTMY(THETA, "deg") as above but THETA is in degrees.
%
% References:
% - Robotics, Vision & Control: Fundamental algorithms in MATLAB, 3rd Ed.
% P.Corke, W.Jachimczyk, R.Pillat, Springer 2023.
% Chapter 2
%
% See also TFORMRY, ROTMX, ROTMZ, ROTM2D, so3.
% Copyright 2022-2023 Peter Corke, Witold Jachimczyk, Remo Pillat
function R = rotmy(theta, unit)
arguments
theta (1,1) = 0
unit (1,1) string {mustBeMember(unit, ["rad", "deg"])} = "rad"
end
assert((isreal(theta) | isa(theta, "sym")), ...
"RVC3:rotmy:badarg", "theta must be a real scalar or symbolic");
if unit == "deg"
theta = deg2rad(theta);
end
ct = cos(theta);
st = sin(theta);
% make almost zero elements exactly zero
if ~isa(theta, "sym")
if abs(st) < eps
st = 0;
end
if abs(ct) < eps
ct = 0;
end
end
% create the rotation matrix
R = [
ct 0 st
0 1 0
-st 0 ct
];
end