plotting a triangle with surf

18 ビュー (過去 30 日間)
Carsten
Carsten 2024 年 11 月 25 日 14:08
コメント済み: Carsten 2024 年 11 月 25 日 14:40
Hi all,
I have plotted a ellipsoid with the surf function and would like to add a triangle to this plot in a way, so that i can specify the height and length of the triangle.
Is this possible?
Thank you for your help!

採用された回答

Abhas
Abhas 2024 年 11 月 25 日 14:17
Yes, you can add a triangle to your existing 3D plot in MATLAB. You can use the "patch" function to create a triangular surface by specifying the vertices of the triangle.
Here's an example to achieve the same:
[x, y, z] = ellipsoid(0, 0, 0, 5, 3, 2, 30);
figure;
surf(x, y, z);
hold on;
% You can adjust these coordinates to change the position, height, and length of the triangle
v1 = [1, 1, 1]; % Vertex 1
v2 = [4, 1, 1]; % Vertex 2
v3 = [1, 4, 3]; % Vertex 3
% Create the triangle using the patch function
patch('Vertices', [v1; v2; v3], 'Faces', [1, 2, 3], 'FaceColor', 'red', 'FaceAlpha', 0.5);
% Set the axis for better visualization
axis equal;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('Ellipsoid with a Triangle');
% Adjust view angle for better visualization
view(3);
You may refer to the below documentation links to know more about "patch": https://www.mathworks.com/help/matlab/ref/patch.html
I hope this helps!
  1 件のコメント
Carsten
Carsten 2024 年 11 月 25 日 14:40
Thank's alot, worked perfectly.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by