How do I plot the angle

73 ビュー (過去 30 日間)
Umut Ayyildiz
Umut Ayyildiz 2019 年 1 月 29 日
回答済み: Brian Hart 2019 年 1 月 30 日
A boat moves at 20kmh^−1 along a straight path described by
y =11x/15+43/3
starting at x = −10; y = 7. Plot the angle (in degrees) of the line of sight from an observer at the coordinate origin to the boat as a function of time for 3 hours.
This is what I have so far
x=-10:20:50
y=((11*x)/15)+(43/3)
plot(x,y)
hold on
a=atand(y/x)
legend('boat')

採用された回答

Brian Hart
Brian Hart 2019 年 1 月 30 日
Hi Umut,
This is a neat problem! Some nice physics with rectangular-to-polar conversions and trig asymptotes. My code to solve the problem is below. There's a fair amount of background knowledge needed to understand the math.
%define constants
vel = 20 / 60; %km/min
slope = 11/15;
lineAngle = atan(slope); %radians
yInt = 43/3;
xStart = -10;
yStart = 7;
tMax = 3*60; %max time in minutes
tInc = 5; %compute for five minute increments
%Make a vector of time values for which to compute x, y position:
tVec = 0:tInc:tMax;
%Compute the radial distance from the starting point at each time interval:
distArr = tVec * vel;
% Compute the x, y position at each time interval:
xArr = xStart + cos(lineAngle) * distArr;
yArr = yStart + sin(lineAngle) * distArr;
figure;plot(xArr,yArr,'x');title('Boat position at each time interval')
origToPtAngle = rad2deg(atan(yArr ./ xArr));
%Because the trajectory crosses x=0, we get a phase error. Crude
%correction:
origToPtAngle(find(origToPtAngle<0))=origToPtAngle(find(origToPtAngle<0)) + 180;
figure;plot(tVec,origToPtAngle,'.-');title('Line-of-sight from origin to boat position vs time in minutes (x-axis = 0°)')
With this I get:
untitled.bmp
untitled1.bmp
There's probably a more elegant way to handle the rectangular-to-polar stuff.

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by