2

我正在寻找一种在 3D 冲浪图中的特定位置绘制圆锥的方法。是否也可以让圆锥体 50% 透明?

现在我正在使用该surf函数绘制一个基本的 3d 环境。我正在尝试使用该功能plot3在特定位置绘制具有特定尺寸的圆锥。

4

2 回答 2

4

下面的代码通过在 0 和 1 之间夹住一个圆柱体来创建一个圆锥体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

他们气缸

于 2013-09-05T17:02:35.620 回答
3

我发现这个功能完全按照我的需要工作:

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个面,颜色为红色,末端不闭合,不画线。

更新:图片示例

matlab中的随机锥

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

希望有帮助。

于 2015-08-19T17:54:06.800 回答