-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEnvironment.m
37 lines (26 loc) · 1.18 KB
/
Environment.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
classdef Environment
properties
ground_data = zeros(2, 5);
end
methods
function obj = Environment(ground_data)
obj.ground_data = ground_data;
end
function terrain = getLocalTerrain(obj, x)
terrain = Terrain();
% Snap center to a multiple of the x stride
npts = numel(terrain.height);
xdiff = (terrain.xend - terrain.xstart) / npts;
x = round(x / xdiff) * xdiff;
% Get the height samples
terrain.xstart = terrain.xstart + x;
terrain.xend = terrain.xend + x;
terrain.height = interp1(obj.ground_data(:, 1), obj.ground_data(:, 2), ...
linspace(terrain.xstart, terrain.xend, npts)');
% Set other parameters using the center value
terrain.stiffness = interp1(obj.ground_data(:, 1), obj.ground_data(:, 3), x);
terrain.damping = interp1(obj.ground_data(:, 1), obj.ground_data(:, 4), x);
terrain.friction = interp1(obj.ground_data(:, 1), obj.ground_data(:, 5), x);
end
end
end