Surface of a equation

3 ビュー (過去 30 日間)
Daniel Jaló
Daniel Jaló 2012 年 9 月 15 日
コメント済み: Walter Roberson 2020 年 11 月 11 日
Hi.
I want to plot the quadratic surface of a sphere:
x^2 + y^2 + z^2 = r , where r is equal to 1. Therefore:
x^2 + y^2 + z^2 = 1, where x, y and z are values between -1.5 and 1.5
Can anyone explain me how to do this? I've looked into mesh surfaces but I can only plot functions ( f(x,y) )..
Any help will be highly appreciated. Thanks.

採用された回答

Wayne King
Wayne King 2012 年 9 月 15 日
編集済み: Wayne King 2012 年 9 月 15 日
I think you meant to square r in your equation, and you cannot have a value between -1.5 and 1.5 if the radius is 1. The radius has to be 1.5. Think about what happens if x=0,y=0,z=1.5 as you stated must be a point that satisfies the equation x^2+y^2+z^2 = r^2
You should probably do it with spherical coordinates:
n = 100;
r = 1.5;
theta = (-n:2:n)/n*pi;
phi = (-n:2:n)'/n*pi/2;
cosphi = cos(phi); cosphi(1) = 0; cosphi(n+1) = 0;
sintheta = sin(theta); sintheta(1) = 0; sintheta(n+1) = 0;
x = r*cosphi*cos(theta);
y = r*cosphi*sintheta;
z = r*sin(phi)*ones(1,n+1);
surf(x,y,z)
xlabel('X'); ylabel('Y'); zlabel('Z')
Note that MATLAB has a function for this with a unit sphere, sphere.m
  2 件のコメント
Varun Dogra
Varun Dogra 2020 年 11 月 11 日
Develop a sweep surface by sweeping a circle P (r, θ) of radius 7.5
units with center at (4,3) along the positive z-axis by 10 units
Please help
Walter Roberson
Walter Roberson 2020 年 11 月 11 日
r = 7.5; xc = 4; yc = 3;
zl = 0; zh = 10;
fimplicit3(@(x,y,z) (x-xc).^2+(y-yc).^2-r^2,[xc-r xc+r yc-r yc+r zl zh], 'edgecolor', 'none')

サインインしてコメントする。

その他の回答 (3 件)

Jürgen
Jürgen 2012 年 9 月 15 日
[x,y,z] = sphere(); r = 5; figure,surf( r*x +cx, r*y+ cy, r*z +cz) wit (cx,,cy,cz) the center look at http://www.mathworks.com/matlabcentral/newsreader/view_thread/169373

Javier
Javier 2012 年 9 月 15 日
編集済み: Walter Roberson 2020 年 11 月 11 日
Procedure done in Matlab R2012.
The problem that you want to solve gives complex solution for Z for arbitrary X and Y in [-1.5,1.5]. The square of X^2 + Y.^2 must be lower than 1, in other case,the solution for Z is a complex number (mesh function doesnt support complex data). To prove it, solve for Z. You get an square root of (1-(X.^2+Y.^2)). I show how to solve for arbitrary number X and Y lower than 0.70 (0.7071^2= 0.5).
Data=randn(10,10) % 10 is arbitrary. Matriz square.
u=find(Data>0.70);
d=find(Data<-0.70);
%Define limits of Data Matriz
Data(u)=0.70;
Data(d)=-0.70;
%Divide Data matriz in two
X=Data(:,1:5);
Y=Data(:,6:10);
%For arbitrary X and Y value Z must solve the equality
Z=feval(@(X,Y)[sqrt(1-(X.^2+Y.^2))],X,Y)
%Plot data
mesh(X,Y,Z)
If this solve your question please grade or make a comment to this answer. Best regards
Javier

auto2060
auto2060 2016 年 11 月 16 日
There is a new function in R2016b: fimplicit3
So
r = 1;
fimplicit3(@(x,y,z) x.^2+y.^2+z.^2-r^2,[-1.5 1.5 -1.5 1.5 -1.5 1.5])

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by