| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3772 人关注过本帖
标题:这个程序能不能画出一棵树出来?
只看楼主 加入收藏
andfuture
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-11-19
收藏
 问题点数:0 回复次数:0 
这个程序能不能画出一棵树出来?
我用matlab一直画不出图形,是哪里出错了吗?
function drawTree(order, theta, x0, y0, trunk, alpha)
% order:树的层数
% theta:枝条张角
% alpha:枝条与地面夹角
% x0,y0: 根的位置
% trunk:枝条长度
pos = [x0 y0];    % 枝条起始位置
posn = pos + [trunk*cos(alpha) trunk*sin(alpha)];    % 枝条末端位置
x = [pos(1) posn(1)]; y = [pos(2) posn(2)]; plot(x,y,'color',[94/256, 38/256, 18/256],'LineWidth',order);     % 画枝条                        
hold on
% Base case
if(order==1)
    % 画树叶
    t = (1/16:1/8:1)'*2*pi;
 xleaf = posn(1) + 0.2*sin(t);
    yleaf = posn(2) + 0.2*cos(t);
    fill(xleaf,yleaf,'r');
    return;
end
% Recursive call
trunk = trunk * 0.7;   % 让枝条变短
drawTree(order-1, theta, posn(1), posn(2), trunk, alpha+theta);  % 画左分支
drawTree(order-1, theta, posn(1), posn(2), trunk, alpha-theta);  % 画右分支
drawTree(order-1, theta, posn(1), posn(2), trunk, alpha);        % 画中支
clf
搜索更多相关主题的帖子: order alpha 位置 cos sin 
2018-04-10 18:56
快速回复:这个程序能不能画出一棵树出来?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016775 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved