matlab画圆柱,Matlab 画三维圆柱体
主要学习了画空间圆柱体和空间长方形的绘制方法。
有两个surface property:'FaceColor'和'EdgeColor’;
先讲'FaceColor’,它指定了surface画出曲面的颜色,可以是[r,g,b]的一个向量,分别表示了红绿蓝的颜色配比;
也可以是'interp’,画出来是由z的值决定的渐变色,可以使用colormapeditor来调节颜色(在代码中写上colormapeditor即可唤出调色板);
然后是'EdgeColor’,它会在曲面的表面画出网格,指定颜色的方法同上。
但是有一个疑问没有解决:就是如何只显示各个棱的网格线,而不是整个面的网格线??这个留待后面继续摸索吧。
surface(x,y,z)函数画出来的图像如果想要平移,可以直接在带入参数时修改。比如,沿z轴正方向平移10,就是surface(x,y,z+10);
最后有一个实现视角自动旋转的小功能:
view(az,el)中,az可以调节物体旋转的角度,el调节摄像机的俯仰角度for i=1:120
view(i*1, 30);
pause(0.01);
end
代码如下:function test()
%%
clear;
clc;
clf;
z_delta = 6;
%% draw head
A = imread('head.jpg');
[x,y,z]=sphere(30);
h0=surface(x,y,z + z_delta,'EdgeColor','none');
rotate(h0, [0,0,1], 90);
set(h0,'CData',A,'FaceColor','texturemap');%texturemap纹理贴图
%% draw body
% FaceColor (orange)
face_color = 'interp'; %[1, 0.6, 0];
edge_color = 'b';
colormapeditor;% up board[x1,y1] = meshgrid(-1:0.1:1, -1:0.1:1);z1 = repmat(-1, 21, 21);h1=surface(x1,y1,z1 + z_delta, 'EdgeColor',edge_color,'FaceColor',face_color);% left boardx2 = repmat(1, 21, 21); y2 = repmat([-1:0.1:1],21,1);for i=1:21 for j=1:21 z2(i,j)=-1-(i-1)*0.25;
endendh2=surface(x2,y2,z2 + z_delta,'EdgeColor',edge_color,'FaceColor',face_color);% right boardx3 = repmat(-1, 21, 21);y3 = repmat([-1:0.1:1],21,1);for i=1:21 for j=1:21 z3(i,j)=-1-(i-1)*0.25; endendh3=surface(x3,y3,z3 + z_delta,'EdgeColor',edge_color,'FaceColor',face_color);%
front boardy4 = repmat(1, 21, 21); %#okx4 = repmat([-1:0.1:1],21,1);for i=1:21 for j=1:21 z4(i,j)=-1-(i-1)*0.25; endendh4=surface(x4,y4,z4 + z_delta,'EdgeColor',edge_color,'FaceColor',face_color);% back boardy5 = repmat(-1, 21, 21);x5 = repmat([-1:0.1:1],21,1);for
i=1:21 for j=1:21 z5(i,j)=-1-(i-1)*0.25; endendh5=surface(x5,y5,z5 + z_delta,'EdgeColor',edge_color,'FaceColor',face_color);%% draw armsrobot = robot_model();r_arm = 0.3;num_of_surf = 36;for i=2:5 if mod(i,2)==1 color_arm = 'r'; else color_arm = 'b'; end [Cylinder(i),
EndPlate1(i), EndPlate2(i)] = cylinder3(robot(i).position, robot(i+1).position, r_arm, num_of_surf, color_arm, 1, 0);endfor i=7:10 if mod(i,2)==1 color_arm = 'r'; else color_arm = 'b'; end [Cylinder(i), EndPlate1(i), EndPlate2(i)] = cylinder3(robot(i).position,
robot(i+1).position, r_arm, num_of_surf, color_arm, 1, 0);end%% rotate the angle of viewgrid on;axis equal;axis fill;for i=1:120 view(i*1, 30); pause(0.01);endend下面是由两个点画出一个空间圆柱体的代码,从CSDN上下载的别人的程序,就拿来直接用于画胳膊了。function [Cylinder, EndPlate1, EndPlate2] = cylinder3(X1,X2,r,n,cyl_color,closed,lines)
%
% This function constructs a cylinder connecting two center points
%
% Usage :
% [Cylinder EndPlate1 EndPlate2] = cylinder3(X1+20,X2,r,n,'r',closed,lines)
%
% Cylinder-------Handle of the cylinder
% EndPlate1------Handle of the Starting End plate
% EndPlate2------Handle of the Ending End plate
% X1 and X2 are the 3x1 vectors of the two points
% r is the radius of the cylinder
% n is the no. of elements on the cylinder circumference (more--> refined)
% cyl_color is the color definition like 'r','b',[0.52 0.52 0.52]
% closed=1 for closed cylinder or 0 for hollow open cylinder
% lines=1 for displaying the line segments on the cylinder 0 for only
% surface
%
% Typical Inputs
% X1=[10 10 10];
% X2=[35 20 40];
% r=1;
% n=20;
% cyl_color='b';
% closed=1;
%
% NOTE: There is a MATLAB function "cylinder" to revolve a curve about an
% axis. This "Cylinder" provides more customization like direction and etc
%%%%%%%%%%
if (X1(1) > X2(1))
tmpX = X1; X1 = X2; X2 = tmpX;
end
% Calculating the length of the cylinder
length_cyl=norm(X2-X1);
% Creating a circle in the YZ plane
t=linspace(0,2*pi,n)';
x2=r*cos(t);
x3=r*sin(t);
% Creating the points in the X-Direction
x1=[0 length_cyl];
% Creating (Extruding) the cylinder points in the X-Directions
xx1=repmat(x1,length(x2),1);
xx2=repmat(x2,1,2);
xx3=repmat(x3,1,2);
% Drawing two filled cirlces to close the cylinder
if closed==1
hold on
EndPlate1=fill3(xx1(:,1),xx2(:,1),xx3(:,1),'r');
EndPlate2=fill3(xx1(:,2),xx2(:,2),xx3(:,2),'r');
end
% Plotting the cylinder along the X-Direction with required length starting
% from Origin
Cylinder=mesh(xx1,xx2,xx3);
% Defining Unit vector along the X-direction
unit_Vx=[1 0 0];
% Calulating the angle between the x direction and the required direction
% of cylinder through dot product
angle_X1X2=acos( dot( unit_Vx,(X2-X1) )/( norm(unit_Vx)*norm(X2-X1)) )*180/pi;
% Finding the axis of rotation (single rotation) to roate the cylinder in
% X-direction to the required arbitrary direction through cross product
axis_rot=cross([1 0 0],(X2-X1) );
% Rotating the plotted cylinder and the end plate circles to the required
% angles
if angle_X1X2~=0 % Rotation is not needed if required direction is along X
rotate(Cylinder,axis_rot,angle_X1X2,[0 0 0])
if closed==1
rotate(EndPlate1,axis_rot,angle_X1X2,[0 0 0])
rotate(EndPlate2,axis_rot,angle_X1X2,[0 0 0])
end
end
% Till now cylinder has only been aligned with the required direction, but
% position starts from the origin. so it will now be shifted to the right
% position
if closed==1
set(EndPlate1,'XData',get(EndPlate1,'XData')+X1(1))
set(EndPlate1,'YData',get(EndPlate1,'YData')+X1(2))
set(EndPlate1,'ZData',get(EndPlate1,'ZData')+X1(3))
set(EndPlate2,'XData',get(EndPlate2,'XData')+X1(1))
set(EndPlate2,'YData',get(EndPlate2,'YData')+X1(2))
set(EndPlate2,'ZData',get(EndPlate2,'ZData')+X1(3))
end
set(Cylinder,'XData',get(Cylinder,'XData')+X1(1))
set(Cylinder,'YData',get(Cylinder,'YData')+X1(2))
set(Cylinder,'ZData',get(Cylinder,'ZData')+X1(3))
% Setting the color to the cylinder and the end plates
set(Cylinder,'FaceColor',cyl_color)
if closed==1
set([EndPlate1 EndPlate2],'FaceColor',cyl_color)
else
EndPlate1=[];
EndPlate2=[];
end
% If lines are not needed making it disapear
if lines==0
set(Cylinder,'EdgeAlpha',0)
end
matlab画圆柱,Matlab 画三维圆柱体相关推荐
- matlab三维圆柱体,matlab画三维圆柱体
数学建模与数学实验 MATLAB作图 二维图形 三维图形 图形处理实例 特殊二.三维图形 作业 1.曲线图 MATLAB作图是通过描点.连线来实现的,故在 画一个曲线图形之前...... 二维图形 三 ...
- matlab如何画一个圆柱,matlab怎么画圆柱
用Matlab 画函数图像一.螺旋线 1.静态螺旋线 a=0:0.1:20*pi... 例 在区间[0,2π]画sin(x),并分别标注"sin(x)""cos(x)&q ...
- matlab画圆柱,使用Matlab画出圆台圆锥圆柱
<使用Matlab画出圆台圆锥圆柱>由会员分享,可在线阅读,更多相关<使用Matlab画出圆台圆锥圆柱(5页珍藏版)>请在人人文库网上搜索. 1.用Matlab画圆柱圆台圆锥自 ...
- 用matlab画树叶,matlab画漂亮的树叶
美丽的树叶 画叶子 1.构出大形 2.增加漂亮的花纹 3.添加环境 找一找你看到了哪些线条 线描树叶: 美丽的树叶 画叶子 1.构出大形 2.增加漂亮的花纹 3...... 方法和材料表现叶子. 叶子 ...
- matlab中画网格,matlab怎么画网格
MATLAB绘制栅格图_数学_自然科学_专业资料.坐标在栅格中心 a = [1 ... Matlab实现 三维图形绘制 ---数学13-2班 陈朋 01 02 前言 1.1.曲线图形绘制 1.2.网格 ...
- 怎么用matlab画误差椭圆,matlab画误差椭圆
一 图4椭圆抛物面 图5双曲抛物面 图6锥面 例如画螺旋曲线的图形,其参数方程设... 数学实验第二次实验报告--MATLAB基本图形绘制_理学_高等教育_教育专区.数... 实验作业 2 解: 代码 ...
- matlab pup,matlab利用bar函数画不同颜色直方图
matlab利用bar函数画直方图,参考文献[1]是matlab官方提供的help文档.里面提供了bar函数的基本用法,但是没有说明如何在同一张图中,为每个bar设置不同的颜色. 例子代码: myda ...
- matlab泰勒图,matlab画泰勒图
急 在matlab中写个用泰勒级数计算arctan(x)的方程 clear;clc;x=1;s=0;y=atan(x);fori=1:1e6n=2*i-1;s=s+(-(-1)^i)*(x^n)/n; ...
- matlab中plot函数画线时 颜色和类型
转自 https://blog.csdn.net/garfielder007/article/details/50449140 matlab里plot函数画线时有很多的颜色和类型可以选择,下面列举一些 ...
最新文章
- 17 个方面,综合对比 Kafka、RabbitMQ、RocketMQ、ActiveMQ 四个分布式消息队列
- 如果遇到Hadoop集群正常,MapReduce作业运行出现错误,如何来查看作业运行日志(图文详解)...
- 【Scratch】青少年蓝桥杯_每日一题_9.09_画圆形渐变螺旋
- Codeforces 1305F Kuroni and the Punishment (随机化)
- 【Node.js】serve 实现目录浏览服务
- 利用CSS变量实现炫酷的悬浮效果
- 08.Eclipse下Ndk开发(使用fmod实现QQ变声功能)
- 密码学专题 非对称加密算法指令概述 RSA
- 服务器的防火墙禁止了对指定通讯端口的访问,使用iptables限制访问网站指定端口...
- 团队编程项目作业1-成员简介及分工
- 天猫运动户外狂欢日来了!700多个大牌要如何回馈消费者
- 我国光伏行业开始向东走
- 人工智能目前有哪些突破?
- ARMv8-A TrustZone概述
- FPGA之道(16)FPGA开发流程之项目方案与FPGA设计方案
- 【PR学习笔记】PR学习笔记之PR快捷键
- 绿色计算产业峰会,易捷行云新一代ARM云平台推动绿色计算产业发展
- dfs深度优先搜索问题
- 两个L组成的括号?(取整符号)
- AWS VPC CNI vs Calico CNI
热门文章
- 进化Unity Editor UX
- 肚子好饿啊 早知道不约Java了_关于饿了的朋友圈说说大全2018 肚子饿肚子好饿肚子很饿...
- 浪潮开卖人工智能裤子丨Facebook走回头路?人工审核政治广告丨甲骨文发布自动化数据库【软件网每日新闻播报│第10-9期】
- Apache POI 实现word(doc/docx)浏览器预览
- 瑞萨单片机复位原因查找
- 计算机c语言期末答案,计算机C语言期末考试复习试题及答案[1]
- 17 个改变世界的数学公式!
- 2012年度十大杰出IT博客之 罗升阳
- Linux中ps -u和ps u的区别
- 5G NR 随机接入RACH流程(4)-- Msg1发送时RA-RNTI的计算及功率控制