Plotting a hexagon consisting of triangles

1 view (last 30 days)
Ezra Dorsch
Ezra Dorsch on 25 Dec 2020
Commented: Image Analyst on 26 Dec 2020
Hi there,
I am having some trouble plotting a hexagon which has triangles inside it as it can be seen in the figure I have attached. I have a 2D array with the nodepoints (x,y) following the shape first around the perimeter of the hexagon before going into the figure for the triangles as indicated in the figure. Now I hav some issues plotting it using a line plot as I have points connected that I don't want to connect as matlab is reading the array top to bottom connectiong the consecutive points. Any help would be greatly appreatiated!!
Cheers!
  2 Comments
Image Analyst
Image Analyst on 25 Dec 2020
Why does your image have a range of values specified in blue for the length of each side of the "hexagon" shape? Anyway, just use sin() and cos() to get the coordinates, and then call plot(). No big deal. But you have to know the length of each side (hence my question about that).
Ezra Dorsch
Ezra Dorsch on 25 Dec 2020
Edited: Ezra Dorsch on 25 Dec 2020
Those are the node points per element. Essentially like for the first element i.e. between node 1 and 9. I have already obtained all the coordintes and stores them in a 2d array. It is no problem plotting the hexagon on its own, when plotting in inner elements is the point where it gets tricky...
EDIT: Yes sorry, the length of each side is 10.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 25 Dec 2020
Did you try this?
angles = 30:60:390;
sideLength = 10;
x1 = sideLength * cosd(angles);
y1 = sideLength * sind(angles);
% Add zeros so it goes back to the origin between each outer side.
x2 = [x1; zeros(1, length(x1))]
y2 = [y1; zeros(1, length(y1))]
x3 = [x1(:); reshape(x2, [], 1)]
y3 = [y1(:); reshape(y2, [], 1)]
plot(x3, y3, 'b-', 'lineWidth', 3);
grid on;
axis square;
  2 Comments
Ezra Dorsch
Ezra Dorsch on 25 Dec 2020
Thanks for the reply! I don't think this works for me as I need to plot all the points within the plot. My array is 91x2 and my first point i.e. the tip of the the hexagon is my origin. I also will have to plot a figure of the deformed shape after applying the stiffness matrix method. Attached is my line of code for the node points.
% Setting up a matrix of node points for the hexagon
% Setting the number of structural members
NumSM = 12;
% Setting the length of each structural member
LengthSM = 10;
% Setting the number of elements making up each structural member
NumElemSM = 8;
% Calculating the number of elements required
NumElems = NumSM*NumElemSM;
% Calculating the number of node; as we have a complete loop
NumNodes = NumSM*NumElemSM-5;
% Setting the angle alpha from the figure
alpha = 30;
alpha = alpha*pi/180; %degrees to radians
% Calculating the position of nodes at the end of structural members
NodePoints = zeros(NumNodes,2);
NodePoints(1,:) = [0 0];%node1
NodePoints(1*NumElemSM+1,:) = [LengthSM*cos(alpha) -LengthSM*sin(alpha)]; %node 9
NodePoints(2*NumElemSM+1,:) = [LengthSM*cos(alpha) -LengthSM-LengthSM*sin(alpha)];%node17
NodePoints(3*NumElemSM+1,:) = [0 -LengthSM-2*LengthSM*sin(alpha)];%node25
NodePoints(4*NumElemSM+1,:) = [-LengthSM*cos(alpha) -LengthSM-LengthSM*sin(alpha)];%node33
NodePoints(5*NumElemSM+1,:) = [-LengthSM*cos(alpha) -LengthSM*sin(alpha)];%node41
%Midpoint Node
NodePoints(11*NumElemSM+3,:) = [0 -LengthSM*(sin(alpha)+0.5)];%node91
% Calculating the position of nodes along the length of structural members
% using the positions of the start and end nodes of structural members
for n=1:1:NumElemSM-1
NodePoints(n+1,:) = NodePoints(1,:)+(NodePoints(1*NumElemSM+1,:)-NodePoints(1,:)).*n/NumElemSM;%nodes 2 to 8
NodePoints(1*NumElemSM+n+1,:) = NodePoints(1*NumElemSM+1,:)+(NodePoints(2*NumElemSM+1,:)-NodePoints(1*NumElemSM+1,:)).*n/NumElemSM;%nodes 10 to 16
NodePoints(2*NumElemSM+n+1,:) = NodePoints(2*NumElemSM+1,:)+(NodePoints(3*NumElemSM+1,:)-NodePoints(2*NumElemSM+1,:)).*n/NumElemSM;%etc. steps of 8
NodePoints(3*NumElemSM+n+1,:) = NodePoints(3*NumElemSM+1,:)+(NodePoints(4*NumElemSM+1,:)-NodePoints(3*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(4*NumElemSM+n+1,:) = NodePoints(4*NumElemSM+1,:)+(NodePoints(5*NumElemSM+1,:)-NodePoints(4*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(5*NumElemSM+n+1,:) = NodePoints(5*NumElemSM+1,:)+(NodePoints(1,:)-NodePoints(5*NumElemSM+1,:)).*n/NumElemSM;
% Calculating the position of nodes along the inner bars
NodePoints(6*NumElemSM+n,:) = NodePoints(1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(1,:)).*n/NumElemSM;
NodePoints(7*NumElemSM+n-1,:) = NodePoints(1*NumElemSM+1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(1*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(8*NumElemSM+n-2,:) = NodePoints(2*NumElemSM+1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(2*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(9*NumElemSM+n-3,:) = NodePoints(3*NumElemSM+1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(3*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(10*NumElemSM+n-4,:) = NodePoints(4*NumElemSM+1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(4*NumElemSM+1,:)).*n/NumElemSM;
NodePoints(11*NumElemSM+n-5,:) = NodePoints(5*NumElemSM+1,:)+(NodePoints(11*NumElemSM+3,:)-NodePoints(5*NumElemSM+1,:)).*n/NumElemSM;
end

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!