Plotting a parametric surface
9 views (last 30 days)
Show older comments
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 Comment
Roger Stafford
on 22 Dec 2013
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.
Answers (1)
Walter Roberson
on 22 Dec 2013
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 Comments
Walter Roberson
on 22 Dec 2013
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
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!