angle between two lines

30 ビュー (過去 30 日間)
Lama Hamadeh
Lama Hamadeh 2021 年 6 月 2 日
コメント済み: LO 2021 年 6 月 3 日
I have the follwoing geometry:
All the blues and whites are knowns. The reds are unknown and need to be determined (specifically speaking θ).
Any help would be appreicted.
Thanks.

回答 (1 件)

LO
LO 2021 年 6 月 2 日
編集済み: LO 2021 年 6 月 2 日
FIRST you get the angle between white and blue (it does not matter which angle, the procedure is the same, you just have to adjust the rotation later on)
METHOD1:
create vectors using points belonging to either white or blue lines
vector1 = [x2,y2,0] - [x1,y1,0];
vector2 = [x3,y3,0] - [x1,y1,0];
Theta = atan2d(norm(cross(vector1, vector2)), dot(vector1, vector2));
METHOD2 (less robust):
poly1=polyfit(x_values_blue,y_values_blue,1); % get coefficient of line passing through the points you have in one line
x=-20:20; % or another range, doesn't matter
y1=poly1(1)*x+poly1(2); % calculate line based on the coefficients found
% repeat the same for the white line
poly2=polyfit(x_values_white,y_values_white,1);
y2=poly2(1)*x+poly2(2);
% here you have the two slopes, calculate the difference to get their angle
beta=atand(poly1(1));
theta=atand(poly2(1));
SECOND you need to create a rotated vector using the angle you just found (to create the red lines)
% define the x- and y-data for the original line we would like to rotate
x = L1_x_values;
y = L1_y_values;
% create a matrix of these points, which will be useful in future calculations
v = [x;y];
% choose a point which will be the center of rotation (in this case the
% origin)
x_center = 0;
y_center = 0;
% create a rotation matrix
center = repmat([x_center; y_center], 1, length(x));
% define a counter-clockwise rotation matrix
theta = Theta ; % the angle you found previously in degrees, using the first method
theta = theta ; % angle measured using the second method, just comment the one you won't use
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
% rotate
s = v - center; % shift points in the plane so that the center of rotation is at the origin
so = R*s; % apply the rotation about the origin
vo = so + center; % shift again so the origin goes back to the desired center of rotation
% pick out the vectors of rotated x- and y-data
x_rotated = vo(1,:);
y_rotated = vo(2,:);
  1 件のコメント
LO
LO 2021 年 6 月 3 日
in your particular case it seems it just a matter of finding the perpendicular to L1, which is a much simpler case than what I have described.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by