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 CenterFile Exchange에서 Lighting, 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