Plot is a straight line when it should be a curve.
2 views (last 30 days)
Show older comments
%Givens
DetectedAst = 20
Theta = DetectedAst
xnot = 125
xCenter = xnot
radiusCR = 20
AngleB = 42 %(is constant)
k1 = 5
tPath = 9*pi
%set up figure
%plot curve
plot(0,0,'kd', 'markerfacecolor', 'k');
hold on;
ts = linspace (0,tPath);
PathXcoords = 5 * (cosd(45 + AngleB) * (ts + k1 * sind(ts/2)) + ...
sind(45+AngleB) * (ts + 1/k1 * cosd(ts/2)));
PathYcoords = 5 * (sind(45 + AngleB) * (ts + k1 * sind(ts/2))...
- cosd(45+AngleB) * (ts + 1/k1 * cosd(ts/2)));
plot(PathXcoords,PathYcoords,'color',[105 105 105]/255);
hold on;
grid on;
axis equal;
%Change axis limits
PathXMax= 5* (cosd(45 + AngleB) * (tPath + k1 * sind(tPath/2))...
+ sind(45+AngleB) * (tPath + 1/k1 * cosd(tPath/2)));
PathYMax = 5* (sind(45 + AngleB) * (tPath + k1 * sind(tPath/2))...
- cosd(45+AngleB) * (tPath + 1/k1 * cosd(tPath/2)));
axis([0,PathXMax, 0, PathYMax]);
%Graph is supposed to look like:
2 Comments
Accepted Answer
darova
on 26 Sep 2019
Look
Also i suggest to write more readable code (even if it's longer)
c1 = cosd(45 + AngleB);
s1 = sind(45 + AngleB);
st = sin(ts/2);
ct = cos(ts/2);
x = 5*c1*(ts + k1*st) + 5*s1*(ts + 1/k1*ct);
y = 5*s1*(ts + k1*st) - 5*c1*(ts + 1/k1*ct);
More Answers (1)
John D'Errico
on 26 Sep 2019
Edited: John D'Errico
on 26 Sep 2019
Is it really a straight line? Seriously? Did you look CAREFULLY at the curve? A PERFECTLY STRAIGHT LINE? (No.) I'll admit that the deviation is small, so you probably did not see it.
It is just not highly curved. For example, consider the term
(ts + 1/k1 * cosd(ts/2)))
ts varies as from 0 to 28.
What is the magnitude of cos(ts/2)? Clearly that cannot exceed +/-1.
Divide that by k1=5?
Now, how does it compare to ts? Essentially, the linear part of that term dominates the nonlinear part, by roughly 100-1.
Basically, your line DOES have curvature. Just not much of it.
If you wish to test my claim, try this:
diff(PathYcoords)./diff(PathXcoords)
Look very carefully at what you see. Is that vector PERFECTLY constant? They would be so if the curve were perfectly a straight line.
Are your parens wrong? That is something we cannot possibly know, because we are given no clue as to what it is that you really need to do. Something is wrong if you expect to see a strongly curved line. But what might be wrong is just your expectation.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!