Plotting a parametric surface
6 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I've been having trouble figuring this out. I'm suppose to plot a parabolic surface of this general eqn on Matlab GUI:
A = sqrt((X-X1)^2 + (Y-Y1)^2 + (Z-Z1)^2) - sqrt((X-X2)^2 + (Y-Y2)^2 + (Z-Z2)^2)
The equation only stands when realistic values of the variables are given. Thus using meshgrid method doesn't work.
So i'm thinking of using parametric equations to solve it by making all X, Y and Z in terms of t.
Any idea which plot should i be using? ezsurf? plot3? Thanks a ton!
1 个评论
Roger Stafford
2013-12-22
That isn't a parabolic surface, it is one branch of a hyperbola of revolution. The two points (X1,Y1,Z1) and (X2,Y2,Z2) are the two focal points and the axis of revolution lies along the line between them.
回答(1 个)
Walter Roberson
2013-12-22
What are "realistic values of the variables"? Is "A" a constant?
If you use meshgrid to calculate an output, you can set the output to NaN at the places that are not relevant.
The kind of plot to use is going to depend on whether "A" is constant or not. If it is not, then you have 3 independent variables together with one output value, leading to a 4D plot. The 4th dimension would have to be represented by something like color or marker shape. But if "A" is a constant then you only have 2 independent variables and so can construct surfaces.
4 个评论
Walter Roberson
2013-12-22
Expressing it without t is not bad. The following is semi-optimized code. t103A and t103B are the two solutions, which differ in the sign of 't81'.
You would ndgrid to get X, Y, Z, and you would calculate these, and you would use
t103A(imag(t103A) ~= 0) = 0;
t103B(imag(t103B) ~= 0) = 0;
after which you should be able to surf(t103A); hold on; surf(t103B)
t2 = (A .^ 2);
t4 = (t2 .^ 2);
t5 = (X .^ 2);
t7 = (X1 + X2);
t9 = (X1 .^ 2);
t10 = 2 .* t9;
t11 = (X2 .^ 2);
t12 = 2 .* t11;
t13 = (Y .^ 2);
t15 = (Y1 + Y2);
t17 = (Y1 .^ 2);
t18 = 2 .* t17;
t19 = (Y2 .^ 2);
t20 = 2 .* t19;
t21 = (Z1 .^ 2);
t23 = (Z1 .* Z2);
t25 = (Z2 .^ 2);
t27 = 4 .* X .* t7 + 4 .* Y .* t15 - t10 - t12 - 4 .* t13 - t18 - t20 - 2 .* t21 + 4 .* t23 - 2 .* t25 - 4 .* t5;
t29 = 4 .* t21;
t30 = 8 .* t23;
t31 = 4 .* t25;
t32 = (X1 - X2);
t33 = (t32 .^ 2);
t37 = (Y1 - Y2);
t46 = t9 - t11 + t17 - t19;
t51 = (t37 .^ 2);
t64 = t21 .^ 2;
t65 = t21 .* Z1;
t75 = t25 .^ 2;
t78 = t46 .^ 2;
t79 = t4 + t2 .* t27 + t5 .* (t29 - t30 + t31 + 4 .* t33) + X .* (8 .* Y .* t32 .* t37 + 8 .* Z1 .* t7 .* Z2 - 4 .* t21 .* t7 - 4 .* t25 .* t7 - 4 .* t46 .* t32) + t13 .* (t29 - t30 + t31 + 4 .* t51) + Y .* (8 .* Z1 .* t15 .* Z2 - 4 .* t21 .* t15 - 4 .* t25 .* t15 - 4 .* t46 .* t37) + t64 - 4 .* Z2 .* t65 + t21 .* (t10 + t12 + t18 + t20 + 6 .* t25) - 4 .* Z1 .* (t9 + t11 + t17 + t19 + t25) .* Z2 + t75 + 2 .* t25 .* (t9 + t11 + t17 + t19) + t78;
t81 = sqrt((t79 .* t2));
t84 = 2 .* X .* X1;
t86 = 2 .* X .* X2;
t88 = 2 .* Y .* Y1;
t90 = 2 .* Y .* Y2;
t103A = 10 ./ (A - Z1 + Z2) ./ (A + Z1 - Z2) .* ((t2 .* (Z1 + Z2)) + t81 - t65 + (Z2 .* t21) + (Z1 .* (t84 - t86 - t9 + t11 + t88 - t90 - t17 + t19 + t25)) - (t25 .* Z2) + (Z2 .* (-t84 + t86 + t9 - t11 - t88 + t90 + t17 - t19))) ./ 20;
t103B = 10 ./ (A - Z1 + Z2) ./ (A + Z1 - Z2) .* ((t2 .* (Z1 + Z2)) - t81 - t65 + (Z2 .* t21) + (Z1 .* (t84 - t86 - t9 + t11 + t88 - t90 - t17 + t19 + t25)) - (t25 .* Z2) + (Z2 .* (-t84 + t86 + t9 - t11 - t88 + t90 + t17 - t19))) ./ 20
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!