<p>You need to change the call to <code>sqrt</code> from:</p>

<pre><code>np.sqrt(xx**2, yy**2)
</code></pre>

<p>to:</p>

<pre><code>np.sqrt(xx**2 + yy**2)
</code></pre>

<p>Otherwise you're passing an array of values to the function and will be returned an array of values for the answer.</p>

<p><a href="https://numpy.org/devdocs/reference/generated/numpy.sqrt.html?highlight=sqrt#numpy.sqrt" rel="nofollow noreferrer">See here</a> for details:</p>

<blockquote>
  <p><code>&gt;&gt;&gt; np.sqrt([1,4,9])</code></p>
  
  <p>array([ 1.,  2.,  3.])</p>
</blockquote>

CC BY-SA 4.0
2019-10-15T02:31:20.297Z
2019-10-15T02:31:20.297Z
user1118321
<p>per this <a href="https://computergraphics.stackexchange.com/a/9250/11312">post</a>, this formula</p>

<p><span class="math-container">$Z = 1 - \sqrt{X^{2} + Y^{2}}$</span></p>

<p>generates a cone where the point is at (0, 0, 1) and it spreads out below that. It meets the x-y plane at the unit circle</p>

<p><a href="https://i.sstatic.net/jtZdE.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jtZdE.png" alt="enter image description here"></a></p>

<p>I am trying to reproduce with Python</p>

<pre><code>ax = plt.figure().gca(projection='3d')
xx, yy = np.meshgrid(np.arange(-1,1.1,.1), np.arange(-1,1.1,.1))
zz = 1 - np.sqrt(xx**2, yy**2)
ax.plot_surface(xx, yy, zz, alpha=.5)
</code></pre>

<p>and get this "roof"</p>

<p><a href="https://i.sstatic.net/8n6z6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8n6z6.png" alt="enter image description here"></a></p>

<p>each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes, what am I missing?</p>

CC BY-SA 4.0
2019-10-15T02:01:07.257Z
Looks like your mesh is undersampled, in that it only has 6 vertices so its an approximate cone.. Can you increase the resolution some how ?
PaulHK
CC BY-SA 4.0
2019-10-15T02:13:05.180Z
@PaulHK each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes
JJJohn
CC BY-SA 4.0
2019-10-15T02:21:00.027Z
What is `np.sqrt(xx**2, yy**2)`? I would expect something like `np.sqrt(xx**2 + yy**2)`. Otherwise you're getting back an array of square roots, right?
user1118321
<3d>
Why does my code to plot a cone actually generate a roof?
JJJohn
# Why does my code to plot a cone actually generate a roof?

(Asked by: username_0 on 2019-10-15)

per this [post](https://computergraphics.stackexchange.com/a/9250/11312), this formula

$Z = 1 - \sqrt{X^{2} + Y^{2}}$

generates a cone where the point is at (0, 0, 1) and it spreads out below that. It meets the x-y plane at the unit circle

[![enter image description here](https://i.sstatic.net/jtZdE.png)](https://i.sstatic.net/jtZdE.png)

I am trying to reproduce with Python

```
ax = plt.figure().gca(projection='3d')
xx, yy = np.meshgrid(np.arange(-1,1.1,.1), np.arange(-1,1.1,.1))
zz = 1 - np.sqrt(xx**2, yy**2)
ax.plot_surface(xx, yy, zz, alpha=.5)

```

and get this "roof"

[![enter image description here](https://i.sstatic.net/8n6z6.png)](https://i.sstatic.net/8n6z6.png)

each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes, what am I missing?

**Tags:** 3d

> **Comments:**
> **username_1**: Looks like your mesh is undersampled, in that it only has 6 vertices so its an approximate cone.. Can you increase the resolution some how ?  
> **username_0**: @username_1 each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes  
> **username_2**: What is `np.sqrt(xx**2, yy**2)`? I would expect something like `np.sqrt(xx**2 + yy**2)`. Otherwise you're getting back an array of square roots, right?  

---

## 1 answers

### Answer by username_2 on 2019-10-15. Score: 2 | Accepted answer

You need to change the call to `sqrt` from:

```
np.sqrt(xx**2, yy**2)

```

to:

```
np.sqrt(xx**2 + yy**2)

```

Otherwise you're passing an array of values to the function and will be returned an array of values for the answer.

[See here](https://numpy.org/devdocs/reference/generated/numpy.sqrt.html?highlight=sqrt#numpy.sqrt) for details:

> `>>> np.sqrt([1,4,9])`
>
> array([ 1., 2., 3.])


---

