Im trying to design a cone where the centre for one of the faces is offset from the centre of the other face, as in the picture
This is the code I've done for a basic cone with two faces. Thanks
[x,y,z]=cylinder([0,10,5,0],100);
z([1,2],:)=0
z([3,4],:)=75;
hm=surf(x,y,z);
axis equal;
direction=[1,0,0];
rotate(hm,direction,90)

 採用された回答

Star Strider
Star Strider 2018 年 4 月 17 日

1 投票

Try this:

a = linspace(0, 2*pi);
ra = 1;
rb = 5;
apex = [rb*cos(a); ra*cos(a)];
base = [rb*sin(a)+rb; ra*sin(a)+ra];
h = 10;
z = [h*ones(size(a)); zeros(size(a))];
figure(1)
surf((apex), (base), z)
axis equal
shading interp
view(80,30)

4 件のコメント

Jonathan Bird
Jonathan Bird 2018 年 4 月 17 日
Thanks again, please could you explain what the function does in words?
Star Strider
Star Strider 2018 年 4 月 17 日
As always, my pleasure.
This works similarly to the cylinder function. It creates two (2x100) matrices, ‘base’ and ‘apex’, consisting of x-coordinates for ‘base’, and y-coordinates for ‘apex’. It then relies on surf to do the requisite plotting. The ‘+rb’ and ‘+ra’ offsets in ‘base’ get the ‘y’ alignments correct, to produce the ‘straight’ side of the cone. The ‘z’ matrix describes the height.
It is straightforward to plot a cone, since all that is necessary is to create one circle with a greater radius than the other. However ‘tilting’ and ‘distorting’ it to get the shape you want requires offsetting the centres so that one side of the cone has the same coordinates, creating the ‘straight’ side. (This is based on my understanding of how surf and the related plots work.)
Jonathan Bird
Jonathan Bird 2018 年 4 月 22 日
If apex is y values and base x values why don't we do surf((base),(apex),z) as we normally do surf(x,y,z)? Please could you also try to explain what the matrix z would look like, I'm guessing its also 2x100 with the value of h in the first row and zeros in the second row? Thanks
Star Strider
Star Strider 2018 年 4 月 22 日

You can certainly rename them and then switch their order in the surf call. Note that ‘apex’ and ‘base’ are each (2x100) matrices. The x-coordinates are cos values, and the y-coordinates are sin values, each forming a different circle. The exact order doesn’t matter, so long as the two circles get drawn. The z-coordinate (another (2x100) matrix) displaces them in the third dimension, forming the cone.

And you’re correct about the structure of z. If you want the z-coordinates to be different, use this:

z = [h1*ones(size(a)); h2*ones(size(a))];

That will plot one circle at ‘h1’ and the other at ‘h2’, forming the cone between those values.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by