Plot is a straight line when it should be a curve.
1 次查看(过去 30 天)
显示 更早的评论
%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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239945/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239946/image.png)
2 个评论
采纳的回答
darova
2019-9-26
Look
![11Untitled.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/239974/11Untitled.png)
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);
更多回答(1 个)
John D'Errico
2019-9-26
编辑:John D'Errico
2019-9-26
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!