matlab畫圓柱,Matlab 畫三維圓柱體

162142065_1_20190526020809613

主要學習了畫空間圓柱體和空間長方形的繪制方法。

有兩個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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/533023.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/533023.shtml
英文地址,請注明出處:http://en.pswp.cn/news/533023.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

matlab類間散度矩陣,協方差矩陣和散布矩陣(散度矩陣)的意義

在機器學習模式識別相關算法中,經常需要求樣本的協方差矩陣C和散布矩陣S。如在PCA主成分分析中,就需要計算樣本的散度矩陣,而有的教材資料是計算協方差矩陣。實質上協方差矩陣和散度矩陣的意義就是一樣的,散布矩陣(散度矩陣)前乘以…

把樹分成森林 matlab,20170106RF_Matlab 隨機森林指的是利用多棵樹對樣本進行訓練并預測的一種分類器,包括兩個方面:數據的隨 269萬源代碼下載- www.pudn.com...

文件名稱: 20170106RF_Matlab下載 收藏√ [5 4 3 2 1 ]開發工具: matlab文件大小: 441 KB上傳時間: 2017-01-06下載次數: 0提 供 者: yanxiu詳細說明:隨機森林指的是利用多棵樹對樣本進行訓練并預測的一種分類器,包括兩個方面:數據的隨…

inur new.php id,Cmsez(隨易)全站系統 0day

程序名稱:Cmsez Web Content Manage System v2.0.0文件:comments.php viewimg.php代碼:---------------//commentsinclude "mainfile.php";$artnew article();//設定$confirmyes;//yes:需要管理員認證后才能顯示,no:直接顯示$membe…

PHP紅黑源碼,紅黑樹的實現源碼(第二次修訂版)

/*-----------------------------------------------------------RB-Tree的插入和刪除操作的實現算法參考資料:1) <>2) http://lxr.linux.no/linux/lib/rbtree.c作者&#xff1a;http://www.cppblog.com/converse/您可以自由的傳播&#xff0c;修改這份代碼&#xff0c;轉…

python 自動點擊上傳以后上傳文件,python使用selenium模擬點擊網頁實現自動導入上傳文件功能...

一、環境準備Python版本&#xff1a;3.4編輯器&#xff1a;Pycharmexcel文件&#xff1a;導入的excel模板二、python代碼由于工作需要&#xff0c;需要每天定時導入相關excel文件進入后臺數據庫&#xff0c;由于導入的邏輯比較復雜&#xff0c;所以決定通過python模擬登陸導入網…

php繪制頻譜圖,一步一步教你實現iOS音頻頻譜動畫(二)

本文是系列文章中的第二篇&#xff0c;上篇講述了音頻播放和頻譜數據計算&#xff0c;本篇講述數據處理和動畫的繪制。前言在上篇文章中我們已經拿到了頻譜數據&#xff0c;也知道了數組每個元素表示的是振幅&#xff0c;那這些數組元素之間有什么關系呢&#xff1f;根據FFT的原…

php刪除尾部字符,php如何刪除字符串末尾字符

我們知道字符串刪除字符的方式有好幾種&#xff0c;今天就來介紹三種php刪除字符串最后一個字符的函數&#xff0c;有需要的小伙伴可以參考一下。方法一&#xff1a;substr()函數substr()函數返回字符串的一部分。語法如下&#xff1a;substr(string string, int start, int [l…

empinfo Oracle數據庫,Oracle數據庫---包

--根據員工號或員工姓名獲取員工的信息--根據員工號或員工姓名刪除員工的信息--創建包規范CREATE OR REPLACE PACKAGE overload_pkgISFUNCTION get_info(eno NUMBER) RETURN emp%ROWTYPE;FUNCTION get_info(name VARCHAR2) RETURN emp%ROWTYPE;PROCEDURE del_emp(eno NUMBER);P…

oracle查看context,oracle context(上下文)

context在計算機領域翻譯為上下文context的信息也就是當前會話中的環境變量&#xff0c;如&#xff1a;登錄的session_id&#xff0c;用戶名&#xff0c;語言等信息查看context中的屬性信息。oracle默認的為我們創建了一個context叫userenv(user environment)SYS_CONTEXT(USERE…

oracle標量子查詢的優勢,標量子查詢

--標量子查詢select e.empno, e.ename, e.sal, e.deptno,(select d.dname from dept d where e.deptno d.deptno)as dnamefrom emp e--插入一條數據insert into emp(empno,deptno) values(9999,null)--返回結果15條記錄--改成left join(hash outer)select e.empno, e.ename, e…

切割照片php上傳,php下ajax的文件切割上傳

var myForm document.getElementById("myForm");var upfile document.getElementById("upfile");myForm.onsubmit function() {//獲取文件對象var file upfile.files[0];//獲取文件大小var fileSize file.size;//一次截取的大小(字節)var CutSize 10…

oracle插補缺失日期,Oracle連接 ORA-28001: 口令已經失效解決方法

cmd進入命令行C:UsersAdministrator>sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on 星期四 9月 24 15:19:21 2020Copyright (c) 1982, 2010, Oracle. All rights reserved.連接到:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Pr…

PHP 蒙太奇馬賽克拼圖,AndreaMosaic制作一幅馬賽克拼圖

大家在網上應該都見過用很多幅圖片拼成的馬賽克圖片&#xff0c;今天小編就為大家介紹AndreaMosaic制作一幅馬賽克拼圖方法&#xff0c;不會的朋友快快來學習吧&#xff01;軟件名稱&#xff1a;AndreaMosaic(蒙太奇圖片制作軟件) V6.1.0.4 中文安裝免費版軟件大小&#xff1a;…

php mongo 查詢count,[PHP] 使用PHP在mongodb中進行count查詢

原文&#xff1a;https://www.cnblogs.com/taoshihan/p/12362111.html在php7的mongodb擴展中&#xff0c;當要查詢某個集合在某個條件下的數據個數時&#xff0c;可以使用下面的方式來獲取。比原生的命令要復雜許多比舊版mongo擴展也復雜許多需要使用到MongoDB\Driver\Command …

oracle字段類型設計,Oracle字段類型設計與實際業務不符引發的問題

在Oracle表的設計過程中&#xff0c;開發人員總是對字段的類型不以為然&#xff0c;下面來演示一個例子&#xff0c;按照應該設計為number的&#xff0c;結果設計成了varcha在Oracle表的設計過程中&#xff0c;開發人員總是對字段的類型不以為然&#xff0c;下面來演示一個例子…

linux下進程監控6,Linux進程監控技術—精通軟件性能測試與LoadRunner最佳實戰(6)...

8.2.5 Linux操作系統進程監控技術Linux在進程監控方面同樣出色&#xff0c;不僅可以通過圖形用戶界面的管理工具&#xff0c;還可以用命令方式顯示進程相關信息。像“Windows的任務管理器”一樣&#xff0c;在RedHat 9中可以通過單擊“系統工具”→“系統監視器”&#xff0c;…

linux pcie命令,setpci命令_Linux setpci 命令用法詳解:查詢和配置PCI設備的使用工具...

setpci命令是一個查詢和配置PCI設備的使用工具。語法setpci(選項)(參數)選項-v&#xff1a;顯示指令執行的細節信息&#xff1b;-f&#xff1a;當沒有任何操作需要完成時&#xff0c;不顯示任何信息&#xff1b;-D&#xff1a;測試模式&#xff0c;并不真正將配置信息寫入寄存器…

linux proc文件 write的原子性,Linux命令之write調用的原子性

linux命令是對Linux系統進行管理的命令。本文介紹的關于linux命令中write調用的原子性的詳細描述&#xff0c;具體內容如下所述。UNIX環境高級編程中關于原子操作的介紹&#xff0c;其中有一種情形是在文件尾端添加數據。文中說&#xff0c;如果多個進程都需要將數據添加到某一…

linux 命令行 迅雷替代,Mac/Linux下迅雷替代方案

還記得我兩年前寫的《DIY了家用NAS》嗎&#xff1f;現在又帶來新的升級啦。當初的NAS最多能使用Transmission來進行BT下載&#xff0c;那時就在想&#xff0c;如果能下載普通的http資源就好了。再進一步&#xff0c;有什么方案可以通吃所有下載方式呢&#xff1f; 記得那個時候…

linux好用的編譯器,推薦幾款Linux下比Notepad++好的編輯器軟件

Notepad這一段又出風頭了&#xff0c;好好的做你軟件多好&#xff0c;非得參雜入政治。前兩天開源文本編輯器 Notepad 發布了 7.8.1 版本&#xff0c;然后在該版本中作者居然摸黑中國&#xff0c;具體的內容請大家自行百度。而且這已經不是 Notepad 第一次這么干了&#xff01;…