How to plot a curve using angles?

I want to plot the 2D curve that passes through a number of points for which I only have the angle (inclination of the curve with respect to the vertical) and the length of the line between each two points. The form of the line should be a spline in order to get a smooth curve of the coordinates y with respect to the coordinates x. Here's an example of the data I have:
s = linspace[0,1000,100]; % Each entry of this vector represents the location of the respctive point on the curve
Inc = linspace[0,1.5708,100] % This is only an example that shuould describe a quadrant, whereas the actual angles that I have are not as perfect
My goal is to get the actual values of x and y for any given point along the curve. Suppose the curve starts from the origin [0,0].
The result obtained from the above data should be your usual quadrant, or something close.
P.S. I'm not all that familiar with MATLAB so please don't leave out any details.
Thanks in advance.

2 Commenti

darova
darova il 14 Apr 2020
Have angles are defined?
As I stated in the question, the angles represent the inclination of the curve with respect to the vetical axis at each respective point so similar to your 1st drawing. Something like this:
Thanks!

Accedi per commentare.

 Risposta accettata

darova
darova il 14 Apr 2020
Try cumsum
ds = rand(1,10); % length of each segment
a = rand(1,10)*90; % angle of each segment
dx = sind(a).*ds; % projection of segment on X axis
dy = cosd(a).*ds; % projection of segment on Y axis
x = [0 cumsum(dx)];
y = [0 cumsum(dy)];
plot(x,y)
See more about cumsum
>> cumsum([1 0 2 1])
ans =
1 1 3 4

6 Commenti

Thank you for your answer. As for the code you suggested, it assumes a straight line between each point which doesn't serve my purpose too well. I need the curve to be smooth so that I can use it for another problem. Isn't there a way to use spline interpolation in this case?
Sure, use spline if x or y is monotonically increasing
x1 = linspace(x(1),x(end),100);
y1 = spline(x,y,x1);
plot(x1,y1)
Ok, so I tried the spline finction and it did give a smooth curve all right. Here's what I got:
but the problem now is that the slope of the interpolated curve doesn't match the angles at eah survey point which it should since those are the real data. Is there any way I can tell the spline fucntion to use the angles at each point instead of only the position of the points to get a curve that complies with those angles? The result could be something like this:
Thanks.
Try to add points close to connection
clc,clear
ds = rand(1,10); % length of each segment
a = rand(1,10)*90; % angle of each segment
dx = sind(a).*ds; % projection of segment on X axis
dy = cosd(a).*ds; % projection of segment on Y axis
x = [0 cumsum(dx)];
y = [0 cumsum(dy)];
x1 = [x; x + 0.05]; % add point
x1 = x1(:);
y1 = interp1(x,y,x1); % get new Y coordinate
x2 = linspace(x(1),x(end),100);
y2 = spline(x1,y1,x2); % create spline
plot(x1,y1,'.-r')
line(x2,y2)
The results definitely seem better:
Thank you so much for taking the time to answer my questions.
darova
darova il 15 Apr 2020
my plesure

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2017b

Richiesto:

il 14 Apr 2020

Commentato:

il 15 Apr 2020

Community Treasure Hunt

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

Start Hunting!

Translated by