Hi i have following code which shows some error how i solve it plzz help
2 ビュー (過去 30 日間)
古いコメントを表示
clear all
clc
syms t x y
%points to define the bezier curve
Px = [10 50 60 70];
Py = [30 60 0 20];
%equation of bezier curve
Pxx = Px(1)*(1-t).^3 + 3*Px(2)*t.*(1-t).^2 + 3*Px(3)*(1-t).*t.^2 + Px(4)*t.^3;
Pyy = Py(1)*(1-t).^3 + 3*Py(2)*t.*(1-t).^2 + 3*Py(3)*(1-t).*t.^2 + Py(4)*t.^3;
Pxd = diff(Pxx);
Pyd = diff(Pyy);
%evaluating points of bezier curve
t=0:0.1:1;
Pxx = Px(1)*(1-t).^3 + 3*Px(2)*t.*(1-t).^2 + 3*Px(3)*(1-t).*t.^2 + Px(4)*t.^3;
Pyy = Py(1)*(1-t).^3 + 3*Py(2)*t.*(1-t).^2 + 3*Py(3)*(1-t).*t.^2 + Py(4)*t.^3;
%calculating slope of normal at any point
X = subs(Pxd,t);
Y = subs(Pyd,t);
M = -(X./Y);
%offset distance (radius of tool/2)
D = [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2];
%unit vector in direction of normal
R = sqrt(1+(M.^2));
%coordinates of pt A
Xa = Pxx+(D./R);
Ya = Pyy+((D.*M)./R);
%coordinates of point C (centre of circle)
Xc = Pxx+(-D./R);
Yc = Pyy+((-D.*M)./R);
%evaluating the intersection circle and line from above point to next point
for t=0:1:10
[L] = solve(((x - Xc)).^2) +(((y - Yc)).^2)-16, (y - Pyy(t))-(((Pyy(t+1)-Pyy(t))./(Pxx(t+1)-Pxx(t))).*(x - Pxx(t)));
Lx = L.x;
Ly = L.y;
%coordinates of point B
Xb = Lx;
Yb = Ly;
%slopes of lines from C to B and from C to A
M1 = (Yb-Yc)/(Xb-Xc);
M2 = (Ya-Yc)/(Xa-Xc);
%Angle of above lines
Theta(t) = atand(double(M1));
Theta(t+1) = atand(double(M2));
%cutter engagement angle
Alpha = Theta(t+1)-Theta(t);
end
0 件のコメント
回答 (2 件)
Walter Roberson
2018 年 2 月 15 日
Change
t=0:0.1:1;
To
T=0:0.1:1;
Then where you have subs(expression, t) use subs(expression, t, T)
Later replace
for t=0:1:10
With
for t=1:length(T)
3 件のコメント
Walter Roberson
2018 年 2 月 19 日
I had to make a lot of guesses about what you are actually trying to do. I didn't bother trying to figure out why, as I suspect your equations are not set up well. I did not try to fix the math: I just fixed the sizes. The code is attached.
In your line
M = -(X./Y);
is M intended to be a slope? Because slope is delta Y divided by delta X, not delta X divided by delta Y.
Basil C.
2018 年 2 月 19 日
There are some errors that I could find
- The slope is change in Y by change in X
M = -(X./Y)
- You cannot have index values starting from zero. So
for t=0:1:10
Should be changed to
for t=1:1:10
- While using the solve function I don't think you can use Xc and Yc directly since they are an array . So change
[L] = solve(((x - Xc)).^2) +(((y - Yc)).^2)-16,...
(y - Pyy(t))-(((Pyy(t+1)-Pyy(t))./(Pxx(t+1)-Pxx(t))).*(x - Pxx(t)));
To
[L] = solve(((x - Xc(t))).^2) +(((y - Yc(t))).^2)-16,...
(y - Pyy(t))-(((Pyy(t+1)-Pyy(t))./(Pxx(t+1)-Pxx(t))).*(x - Pxx(t)));
Where I have used Yc(t) and Xc(t) rather than just Yc and Xc. This maybe wrong so make the changes accordingly
- Again you cannot subtract matrix with unequal sizes in
M1 = (Yb-Yc)/(Xb-Xc);
M2 = (Ya-Yc)/(Xa-Xc);
So change it to something like:
M1 = (Yb(t)-Yc(t))/(Xb(t)-Xc(t));
M2 = (Ya(t)-Yc(t))/(Xa(t)-Xc(t));
2 件のコメント
Walter Roberson
2018 年 2 月 20 日
What next? Well you could try the complete code that I attached to my answer. You should review it though as you had a syntax error that I had to guess at the meaning of. The code I posted should be quite clear as to how the sub expressions are built up: always write for clarity first and then if you ever need to combine parts for efficiency you will have a model to compare against to be sure that you get the brackets right.
参考
カテゴリ
Help Center および File Exchange で MuPAD についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!