plotting a triangle with surf
18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Carsten
am 25 Nov. 2024 um 14:08
Kommentiert: Carsten
am 25 Nov. 2024 um 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!
0 Kommentare
Akzeptierte Antwort
Abhas
am 25 Nov. 2024 um 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!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Lighting, Transparency, and Shading finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!