【发布时间】:2013-09-05 16:27:10
【问题描述】:
我正在寻找一种在 3D 冲浪图中的特定位置绘制圆锥的方法。是否也可以让圆锥体 50% 透明?
现在我正在使用surf 函数绘制一个基本的 3d 环境。我正在尝试使用函数plot3 在特定位置绘制具有特定尺寸的圆锥。
【问题讨论】:
标签: matlab user-interface plot draw
我正在寻找一种在 3D 冲浪图中的特定位置绘制圆锥的方法。是否也可以让圆锥体 50% 透明?
现在我正在使用surf 函数绘制一个基本的 3d 环境。我正在尝试使用函数plot3 在特定位置绘制具有特定尺寸的圆锥。
【问题讨论】:
标签: matlab user-interface plot draw
以下代码通过使用t=[0;1] 将圆柱体夹在零和一之间来创建一个圆锥体。然后使用 alpha(...) 函数 fan 来设置透明度。要重新定位圆柱体,您必须向 x、y 或 z 添加一个值或执行旋转(超出此答案的范围)。
t = [0;1];
[X,Y,Z] = cylinder(t);
figure;
clf;
surf(X,Y,Z);
alpha(.5)
hold all
surf(X+1,Y,Z);
alpha(.5);
axis equal
【讨论】:
h = surf(X,Y,Z);rotate(h, [1 0 0], 45);
t 更改为t=[0, .5] 以更改打开角度。
我发现这个功能完全符合我的需要:
http://www.mathworks.com/matlabcentral/fileexchange/21951-cone/content//Cone.m
function [Cone,EndPlate1,EndPlate2] = Cone(X1,X2,R,n,cyl_color,closed,lines)
%
% This function constructs a cylinder connecting two center points
%
% Usage :
% [Cone,EndPlate1,EndPlate2] = Cone(X1,X2,R,n,cyl_color,closed,lines)
%
% Cone-------Handle of the cone
% 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/cone R(1) = start radius, R(2) = end radius
% 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 5];
% 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
这是我最终使用该功能的方式...
给定一个中心点c 和一个单位向量uv,以及圆柱体的高度h 和半径r,这是最终的用法:
Cone(c,c+uv*h,[0,r],20,'r',0,0);
最后四个参数是20个面,颜色为红色,末端不闭合,不画线。
更新:图片示例
clearvars
close all
format compact
C = {'k','b','r','g','y',[.5 .6 .7],[.8 .2 .6]}; % Cell array of colros.
% rng(17);% set a seed
num_faces = 20;
closed = 0;
draw_edges = 1;
figure
hold on
axis equal
set(gca, 'Projection', 'orthographic');
for i = 1:5
radius = rand(1);
% get two end points
end_pts = rand(2,3);
% draw the cone
Cone(end_pts(1,:), end_pts(2,:),[0, radius], ...
20, C{mod(i,7)+1},closed, draw_edges)
alpha(0.3)
end
Cone 函数是 Cylinder 函数的变体,也有人在 fileexchange 上发布:
http://www.mathworks.com/matlabcentral/fileexchange/13995-cylinder/content/Cylinder.m
希望对您有所帮助。
【讨论】: