Angles from different triangles calculated simultaneously - Matrix Dimension Problem and Storage of values
古いコメントを表示
Hello, I am trying to obtain 100 different triangles and calculated their respective angles, as seen the variable "x" contains the range. However, I am having troubles due to matrix dimensions and storage of the angles calculate.
clear
clc
x = -0.06:0.001:-0.012;
%x = -0.012;
Counter = 0:1:100;
while true
Counter = Counter + 1;
% Choose any 3 points of the rectangle
p1 = [-0.06541 0.2458];
p2 = [x 0];
p3 = [0 0];
% Make vectors along each edge of the triangle
v12 = p2-p1;
v13 = p3-p1;
v23 = p3-p2;
% Normalise those vectors
u12 = v12/norm(v12);
u13 = v13/norm(v13);
u23 = v23/norm(v23);
% Compute angles as the acos of their dot products
angle1 = acos(dot(u12, u13, 2));
angle2 = acos(dot(u23, -u12, 2));
angle3 = pi - angle1 - angle2;
% Transforming radians to Degrees
angle_d1 = angle1*180./pi;
angle_d2 = angle2*180./pi;
angle_d3 = angle3*180./pi;
% Display
%figure, plot(p1(1),p1(2),'b.',p2(1),p2(2),'g.',p3(1),p3(2),'m.'), axis equal, hold on
% text(p1(1),p1(2),sprintf('Pt1 (%d deg)',round(angle1/pi*180)))
% text(p2(1),p2(2),sprintf('Pt2 (%d deg)',round(angle2/pi*180)))
%text(p3(1),p3(2),sprintf('Pt3 (%d deg)',round(angle3/pi*180)))
break
end
4 件のコメント
Jan
2021 年 4 月 13 日
You mention, that you have troubles, but do not explain, what they are.
Which "matrix dimensions" cause troubles and how do you want to store the angles?
Edwin Espin
2021 年 4 月 14 日
Jan
2021 年 4 月 14 日
I still do not understand, what you want to achieve. (By the way, no need for apologies: This forum is thought for Matlab questions and of course it is the nature of problems that some details are not clear yet :-) )
What does this mean: "obtain 100 different triangles and calculated their respective angles"?
I suggest to start explaining, what your inputs are. Then mention, how you want to calculate which output. A small working example can help. The code you have tried is useful also.
Instead of "it appears an error of Matrix Dimensions" or "it was a problem of not being possible to use vectors", post a copy of the complete error message, because this can contain important details.
What is the purpose of this code:
Angles(i) = acos((diff(data1) * diff(data2).') / ...
(sqrt(sum(diff(data1).^2, 2)) * sqrt(sum(diff(data2).^2, 2))))
diff(data1) * diff(data2).' is a matrix. Then do you really mean the matrix division / or the elementwise division ./ ? In both cases, the result is not a scalar, so you cannot assign it to Angles(i). But what is correct? Do you expect the output to be a scalar or do you want to store a list of arrays in Angles?
The code of the question contains:
Counter = 0:1:100;
while true
Counter = Counter + 1;
...
break
end
Because the loop is stopped in the firt iteration, you can omit the WHILE/END. The variable Counter is not used anywhere, so what is its purpose? Do you really want to create a vector and increment all of its elements by 1?
Edwin Espin
2021 年 4 月 14 日
採用された回答
その他の回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
