【运动学】基于matlab GUI模拟投篮系统(角度+力度可调)【含Matlab源码 1114期】

举报
海神之光 发表于 2022/05/29 01:31:33 2022/05/29
【摘要】 一、获取代码方式 获取代码方式1: 完整代码已上传我的资源:【运动学】基于matlab GUI模拟投篮系统(角度+力度可调)【含Matlab源码 1114期】 获取代码方式2: 通过订阅紫极神光博客付...

一、获取代码方式

获取代码方式1:
完整代码已上传我的资源:【运动学】基于matlab GUI模拟投篮系统(角度+力度可调)【含Matlab源码 1114期】

获取代码方式2:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。

备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);

二、部分源代码

%% -------------------- copy right --------------------
%
% date        : 2021-3-3
% description : several uicontrols and 3D bascket ring, allow to change
%               view angle freely with four default view angles
% 

%% -------------------- global setting --------------------
clear all;
h = figure('numbertitle','off','name','Shoot Backetball 3D');

%% -------------------- axis setting --------------------
axis tight;
axis([-10, 10, -10, 10, 0, 5]);
%axis off

%% -------------------- draw basket --------------------
hold on;
r = 2;
[a, b, c] = cylinder(r, 30);
mesh((a+8), b, (c/4)+2.8)

%% -------------------- draw background & wall --------------------
% draw ground
ground_x = [-10 10 10 -10];
ground_y = [-10 -10 10 10];
h_ground = fill(ground_x, ground_y, [1 0.4 0]);
two_pts_line_width   = 2;
three_pts_line_width = 3;

% draw 2 points and 3 points lines
z_line       = [0 0];
x_side_line  = [-5 10];
x_mid_line   = [-5 -5];
y_mid_line   = [-3 3];
y_left_line  = [-3 -5];
y_right_line = [3 5];
plot3(x_mid_line, y_mid_line, z_line, 'LineWidth', two_pts_line_width, 'Color', 'w');
plot3(x_side_line, y_left_line, z_line, 'LineWidth', two_pts_line_width, 'Color', 'w');
plot3(x_side_line, y_right_line, z_line, 'LineWidth', two_pts_line_width, 'Color', 'w');
t = 0:pi/50:10*pi;
line((3*sin(t) - 5), 3*cos(t), 'LineWidth', two_pts_line_width, 'Color', 'w');
line((20*sin(t) + 10), 10*cos(t), 'LineWidth', three_pts_line_width, 'Color', 'w');

% draw board
board_x = [0, 0, 0, 0, 0];
board_y = [0, 0, 10, 10, 0];
board_z = [1, 3, 3, 1, 1];
plot3((board_x+10), (board_y-5), (board_z+2), 'LineWidth', 3, 'Color', 'b');
small_board_x = [0, 0, 0, 0, 0];
small_board_y = [0, 0, 4, 4, 0];
small_board_z = [1, 2, 2, 1, 1];
plot3((small_board_x+10), (small_board_y-2), (small_board_z+2), 'LineWidth', 2, 'Color', 'b');
grid on

%% -------------------- user interface control --------------------
% close pushbutton
uicontrol(h, 'Style', 'pushbutton','Position', [250 0 50 30], 'String', 'Close', ...
          'CallBack', 'close', 'BackgroundColor', 'r', 'FontWeight', 'bold');

% height angle slide
slide_height_an = uicontrol(h, 'Style', 'slider', 'Position', [10 370 140 20], ...
                            'Min', 0, 'Max', 90, 'Value', 45, 'BackgroundColor', 'y', ...
                            'CallBack', 'set(text_height_cur,''String'',num2str(get(slide_height_an,''Value'')))');
text_height_min = uicontrol(h, 'Style', 'text', 'Position', [10 390 40 20], ...
                            'String', num2str(get(slide_height_an, 'Min')));
text_height_max = uicontrol(h, 'Style', 'text', 'Position', [110 390 40 20], ...
                            'String', num2str(get(slide_height_an, 'Max')));
text_height_cur = uicontrol(h, 'Style', 'text', 'Position', [60 390 40 20], ...
                            'String', num2str(get(slide_height_an, 'Value')), ...
                            'BackgroundColor', 'y', 'FontAngle', 'italic', 'FontWeight', 'bold');

% direction angle slide
slide_direct_an = uicontrol(h, 'Style', 'slider', 'Position', [410 370 140 20], ...
                            'Min', -90, 'Max', 90, 'Value', 0, 'BackgroundColor', 'c', ...
                            'CallBack', 'set(text_direct_cur,''String'',num2str(get(slide_direct_an,''Value'')))');
text_direct_min = uicontrol(h, 'Style', 'text', 'Position', [410 390 40 20], ...
                            'String', num2str(get(slide_direct_an, 'Min')));
text_direct_max = uicontrol(h, 'Style', 'text', 'Position', [510 390 40 20], ...
                            'String', num2str(get(slide_direct_an, 'Max')));
text_direct_cur = uicontrol(h, 'Style', 'text', 'Position', [460 390 40 20], ...
                            'String', num2str(get(slide_direct_an, 'Value')), ...
                            'BackgroundColor', 'c', 'FontAngle', 'italic', 'FontWeight', 'bold');
% velocity edit
text_v = uicontrol(h, 'Style', 'text', 'Position', [210 390 20 20], 'String', 'm/s');
edit_v = uicontrol(h, 'Style', 'edit', 'Position', [170 390 40 20], 'String', '6', ...
                   'CallBack', 'get(edit_v, ''String'')', 'BackgroundColor', 'w');
function victory = sun_is_fool (place, height, angle_y, angle_z, velocity, gravity)

x = 0:0.01:10;
y = 0:0.01:10;
z = 0:0.01:10;

miss_y = 8;                       %左右角度误差量
miss_v = 0.25;                     %速度误差量
miss_z = 10;                       %上下误差量

victory = 0;

angle_z  = angle_z + miss_z  * (rand - 0.5);
angle_y  = angle_y + miss_y  * (rand - 0.5);
velocity = velocity + miss_v * (rand - 0.5);

vx = velocity * cosd(angle_y) * cosd(angle_z);
vy = velocity * sind(-angle_y) * cosd(angle_z);
vz = velocity * sind(angle_z);

x(1) = -10;
y(1) = place;
z(1) = height;

% variables for audio playing
t_audio = 2;
[yy, fs] = audioread('shots.wav');
% end of variables for audio playing

for t = 2:500
    
    x(t) = x(t-1) + vx * 0.02;
    y(t) = y(t-1) + vy * 0.02;
    z(t) = z(t-1) + vz * 0.02 - 0.5 * gravity * 0.02^2;
    
    vz = vz - gravity * 0.02;
    
    place = (x(t) - 8)^2 + y(t)^2;
    
    if z(t) < 0.4
        
        z(t) = 0.4;
        vz   = - vz * 0.4; 
        if vx ~= 0
            vx = vx * 0.4;
        end
        if vy ~= 0
            vy = vy * 0.4;
        end

    end

    if place < 2 && z(t-1) >= 3.05 &&z(t) <= 3.05 
        
        vx = 0;
        vy = 0;
        victory = 1;
	t_audio = t;
    end
    
    if place >= 2 && place <= 9 && z(t-1) >= 3.45 && z(t) <= 3.45;
        
        vz = - vz * 0.4;
        
        if x(t) <= 9 && x(t) >=7
            
            if vy > 0
               vy = vy - rand;
            elseif vy < 0
               vy = vy + rand;
            end
            
        else
            
            if vx > 0
               vx = vx - rand;
            elseif vx < 0
               vx = vx + rand;
            end
            
        end
        
    end
        
    if x(t-1) <= 9 && x(t) >= 9
        
        vx = - vx * 0.65;
        
    end
    
    if abs(y(t-1)) <= 9 && abs(y(t)) >= 9
        
        vy = - vy * 0.65;
        
    end
    
end

x(501) = -1000;
y(501) = -1000;
z(501) = -1000;

%画球球
[x_b, y_b, z_b] = sphere(30);
X_b = x_b + x(1);
Y_b = y_b + y(1);
Z_b = z_b ./ 2.5 + z(1);
h   = mesh(X_b, Y_b, Z_b);

for k = 2:501
    %绘制篮球
    X = x_b + x(k);
    Y = y_b + y(k);
    Z = z_b ./ 2.5 + z(k);
    set(h, 'XData', X);
    set(h, 'YData', Y);
    set(h, 'ZData', Z);
    
    % add audio
    if  (t_audio ~= 2) && (k == t_audio)
        audioplayer(yy, fs);
    end 
    % end of audio
    
    drawnow;
end


  
 
  • 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
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214

三、运行结果

在这里插入图片描述
在这里插入图片描述

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 门云阁.MATLAB物理计算与可视化[M].清华大学出版社,2013.

文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。

原文链接:qq912100926.blog.csdn.net/article/details/118771573

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。