Hello everyone
Okay, so I have a 40×3 matrix with nodal point IDs. This can then be broken down into x and y coordinates per nodal point. Each line in the 40×3 matrix represents a triangle. I'm trying to make node identification go in a counter-clockwise direction. I've used the equation in the code below to calculate the polygon (triangle) area. For those values that are positive, the direction is counter-clockwise. For negative values it is clockwise. Its roughly 50/50.
What I'm trying to do is use a for loop, so some other method, to make the nodal identification direction change. So instead of having x1 y1, x2 y2, x3 y3, I want x1 y1, x3 y3, x2 y2. I've been mulling over this for a few days, looking online to see if anyone has had similar ideas but I can't find anything. For what I have down below, I keep getting an error. And obviously that wouldn't be the full way of doing it, but it was a way I was going to try.
Any help would be greatly appreciated.
My code:
%%Determing boundary nodes
Tri.triangles=R.ci;Tri.triX=x(Tri.triangles); Tri.triY=y(Tri.triangles);x1=Tri.triX(:,1); y1=Tri.triY(:,1);x2=Tri.triX(:,2); y2=Tri.triY(:,2);x3=Tri.triX(:,3); y3=Tri.triY(:,3);% direction of triangle circulation, +ive is counterclockwise
for i=1:length(Tri.triangles);Tri.area(i)=0.5*((x1(i)*y2(i))-(x2(i)*y3(i))+(x2(i)*y3(i))-(x3(i)*y2(i)));T_area=Tri.area';t_neg(i)=T_area(i)<0; T_neg=t_neg';endT_neg=double(T_neg); bb=x1(T_neg(x1)>0);
Error:
Subscript indices must either be real positive integers or logicals.
T_area=
-0.338828523177654-0.565042113652453-0.9039581664255820.00953685300191864-0.271408101485577-0.6702826276305130.3704162486246790.260899886256084-0.225398410111666-0.00953673134790734-0.8262277249596080.826595614606049-0.4188182524521840.1171105235698630.0329695575637743-0.0329722759779543-1.57312464073766-0.6587505433708430.658923690207303-0.155193869140930-0.08845718717202540.2758313391823320.0546458313474432-0.325210246955976-0.1171147511922750.2863145788433030.4946729913353920.5693078637123110.8716220487840470.1215348113328221.573875806760040.169117909390479-0.324359477497637-0.185630145482719-0.4024708848446610.402549884282053-0.2862962539074940.05466005962807690.4035490192472940.0615939649869688
Best Answer