-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwall.m
executable file
·133 lines (114 loc) · 4.45 KB
/
wall.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
classdef wall
%A wall for climbing, with creation and visualization utilities
properties
holds
width
height
num_width
num_height
width_space
height_space
offset
num_holds
final_hold
%holds: nx2 of [x,y] handhold coordinates in ABS
end
methods
% constructor
function this = wall(info, final_hold)
%Set info settings
if length(info) >= 7
this.width = info(1);
this.height = info(2);
this.num_width = info(3);
this.num_height = info(4);
this.width_space = info(5);
this.height_space = info(6);
this.offset = info(7);
this.final_hold = final_hold;
end
%Select random, uniform, or tiered wall
if length(info) == 9
this.num_holds = info(8);
this.holds = this.tiered_wall();
elseif length(info) == 8
this.num_holds = info(8);
this.holds = this.random_wall();
elseif length(info) == 7
this.holds = this.uniform_wall();
elseif length(info) == 3 %create from CV
this.final_hold = final_hold;
this.holds = this.cv_wall(info{1}, this.final_hold);
this.width = info{2};
this.height = info{3};
end
end
function my_holds = uniform_wall(this)
%make a uniform wall
my_holds = [];
for x = this.offset:this.width_space:this.width_space*this.num_width+this.offset
for y= this.offset:this.height_space:this.height_space*this.num_height+this.offset
my_holds(end+1,:) = [x y];
end
end
if ~ismember(this.final_hold,my_holds,'rows') %add final_hold if not already there
my_holds(end+1,:) = this.final_hold;
end
end
function my_holds = random_wall(this)
%make a randomized wall
my_holds = [];
for i=1:1:this.num_holds
my_holds(i,:) = [this.offset+(this.width-2*this.offset)*rand(), this.offset+(this.height-2*this.offset)*rand()];
end
if ~ismember(this.final_hold,my_holds,'rows') %add final_hold if not already there
my_holds(end+1,:) = this.final_hold;
end
end
function my_holds = tiered_wall(this)
MIX = .6; %level of random offset, 1 is half spacing
%make a wall with three tiers
num_third = this.num_height/3;
%bottom: uniform
my_holds = [];
for x = this.offset:this.width_space:this.width_space*this.num_width+this.offset
for y= this.offset:this.height_space:this.height_space*(floor(num_third)-1)+this.offset
my_holds(end+1,:) = [x y];
end
end
%middle: uniform with random offset
for x = this.offset:this.width_space:this.width_space*this.num_width+this.offset
for y = this.height_space*(floor(num_third))+this.offset:this.height_space:this.height_space*2*floor(num_third)
my_holds(end+1,:) = [x+this.width_space*(rand()-.5)*MIX y+this.height_space*(rand()-.5)*MIX];
end
end
%top: uniform with more severe random offset
this.offset+(this.width-2*this.offset)*rand();
for i=1:this.num_holds
my_holds(end+1,:) = [this.offset+(this.num_width*this.width_space)*rand()...
this.height_space*(2*floor(num_third)) + this.height_space * (floor(num_third)+2) *rand()];
end
% for i=1:1:num_holds
% my_holds(i,:) = [max_width*rand(), max_height*rand()];
% end
if ~ismember(this.final_hold,my_holds,'rows') %add final_hold if not already there
my_holds(end+1,:) = this.final_hold;
end
end
function my_holds = cv_wall(~, my_holds, final_hold)
%make a wall from cv
if ~ismember(final_hold,my_holds,'rows') %add final_hold if not already there
my_holds(end+1,:) = final_hold;
end
end
% utilities
function output = plot_wall(this)
hold on
scatter(this.holds(:,1),this.holds(:,2),25,'black','o','LineWidth',1)
axis equal
axis([0 this.width 0 this.height]);
pbaspect([1 1 1]);
output = gcf;
end
end
end