specifying the coordinates of the corners of astraight line segments

1 次查看(过去 30 天)
i have tried multiple different ways but always end up with errors, i need to make the following equation into a loop
The initial point is x0 = (0, 0)T and the initial direction is along a unit vector d0 = (1, 0)T .
the angel i get from a row vector consisting of alternating length and angle specifications [l1, φ1, l2, φ2, . . . ].
the l_n is always the same, but the angel changes, i split it up so i got 2 vectors, 1 with the length and 1 with the angels.
idk if it is enough information, in short, i want the equation to run the same number of times there is l_n in the vector.
if anymore information is needed let me know, and thanks in advance

回答(1 个)

DGM
DGM 2021-8-13
Something like this?
pt0 = [0 0]; % initial position [x y]
segl = 1; % segment length
N = 10; % number of segments
% these are the polar component vectors
segments = ones(1,N)*segl;
angles = [0 45 90 45 -90 180 -135 -180 45 90];
% convert to rectangular deltas
pts = [segments.*cosd(angles); segments.*sind(angles)].';
% accumulate deltas
pts = cumsum([pt0; pts],1);
plot(pts(:,1),pts(:,2))
If the angles are relative, you could just do cumsum on the angle vector before converting.

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by