# Draw surface of a football (American)

조회 수: 5 (최근 30일)
Szabolcs Simon-Guth . 2021년 11월 5일
댓글: Szabolcs Simon-Guth . 2021년 11월 5일
Hi everyone!
I got the following assignment:
Draw the surface of an american football which can be described with the following equation: within the interval The surface should look like this: I have the following code:
r = linspace(-1,1,21);
a = linspace(0,2*pi,63);
[R,A] = meshgrid(r,a);
X = R.*cos(A);
Y = R.*sin(A);
Z = acos(R);
surf(X,Y,Z);
axis equal
But every time I run the code, I get the following surface: What is it that I am doing wrong?
Thank you for any help that anyone could provide, in advance!

댓글을 달려면 로그인하십시오.

### 채택된 답변

DGM 2021년 11월 5일
편집: DGM 님. 2021년 11월 5일
Two things to notice: note the way your points are spaced unevenly along z compared to the reference image. Also note the restricted domain of acos(). This problem would be easier approached by using z as the parameter instead of r.
z = linspace(-pi/2,pi/2,21);
th = linspace(0,2*pi,63).';
X = cos(z).*cos(th);
Y = cos(z).*sin(th);
Z = repmat(z,numel(th),1);
surf(X,Y,Z);
axis equal
colormap(jet) If you really wanted to do it your way, you could ...
clf; % reset web-plot
r = linspace(0,1,21);
a = linspace(0,2*pi,63);
[R,A] = meshgrid(r,a);
X = R.*cos(A);
Y = R.*sin(A);
Z = acos(R);
surf(X,Y,Z); hold on
surf(X,Y,-Z)
axis equal ##### 댓글 수: 1없음 표시없음 숨기기
Szabolcs Simon-Guth 2021년 11월 5일
Thank you very much for your guidance! I'm new to MATLAB and I didn't think of the fact that the restricted domain, because I concentrated too much on the coding aspect, instead of the maths. Thank you again for all the help! :)

댓글을 달려면 로그인하십시오.

### 추가 답변 (1개)

Yongjian Feng 2021년 11월 5일
편집: Yongjian Feng 님. 2021년 11월 5일
Hint: your assignment states z should be -Pi/2 < z < Pi/2.
But your r range is (-1, 1), which corresponds to z range 0<z< Pi
In other words, you plot the wrong range of Z. The first plot has Z from about -1.5 to 1.5.
Your plot has Z between 0 < Z < 3.
##### 댓글 수: 1없음 표시없음 숨기기
Szabolcs Simon-Guth 2021년 11월 5일
Alright! I understand. So, I'm going to include these parameters as well. Thank you very much for your help! I did not think of that.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!