# Contour plot for triangular element

27 views (last 30 days)
Torkan on 10 Dec 2018
Answered: Cyrus Monteiro on 29 Jun 2023
Does anybody know how can we plot any contour plot in a plate with triangular elements?
Hamza SAYYOU on 16 Jun 2023

Cyrus Monteiro on 29 Jun 2023
To plot a contour plot on a plate with triangular elements, you can follow these steps:
1. Define the coordinates of the nodes and the connectivity of the triangular elements. Each node should have its x, y, and z coordinates, and the connectivity should specify which nodes form each triangular element.
2. Calculate the values of the variable you want to visualize (e.g., temperature, stress, etc.) at each node. These values will be used for the contour plot.
3. Use the `trisurf` function in MATLAB to plot the triangular elements. Provide the node coordinates and connectivity as input to the `trisurf` function.
4. Use the `tricontour` or `tricontourf` function in MATLAB to add contour lines or filled contours to the plot. Provide the node coordinates, connectivity, and the values of the variable as input to the `tricontour` or `tricontourf` function.
Here's an example code snippet that demonstrates plotting a contour plot on a plate with triangular elements:
% Define the node coordinates and connectivity of the triangular elements
nodes = [x1, y1, z1; x2, y2, z2; x3, y3, z3; ...]; % Node coordinates
connectivity = [n1, n2, n3; n4, n5, n6; ...]; % Connectivity of triangular elements
% Calculate the values of the variable at each node
variableValues = [value1; value2; value3; ...]; % Values of the variable
% Plot the triangular elements
trisurf(connectivity, nodes(:, 1), nodes(:, 2), nodes(:, 3));
% Add contour lines or filled contours to the plot
tricontour(nodes(:, 1), nodes(:, 2), connectivity, variableValues);
% or
tricontourf(nodes(:, 1), nodes(:, 2), connectivity, variableValues);
In the code above, replace `x1`, `y1`, `z1`, `n1`, `value1`, and so on with the actual values of the nodes, connectivity, and variable values for your specific case.
The `trisurf` function is used to plot the triangular elements, while the `tricontour` or `tricontourf` function is used to add contour lines or filled contours to the plot based on the variable values.
Make sure to customize the code according to your specific data and requirements.