# Plotting a Sphere with Inputs of Radius and center

**URL:** <https://discourse.julialang.org/t/plotting-a-sphere-with-inputs-of-radius-and-center/85978>\
**Category:** General Usage\
**Tags:** plotting, plots, plotlyjs\
**Created:** [August 19, 2022, 7:36am UTC](https://discourse.julialang.org/t/plotting-a-sphere-with-inputs-of-radius-and-center/85978 "2022-08-19T07:36:24Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 19, 2022, 8:29am UTC](https://discourse.julialang.org/t/plotting-a-sphere-with-inputs-of-radius-and-center/85978/2 "2022-08-19T08:29:16Z")

</div>

Would it be OK to define a `sphere` function:

```julia
using Plots; plotlyjs()

function sphere(r, C) # r: radius; C: center [cx,cy,cz]
    n = 100
    u = range(-π, π; length = n)
    v = range(0, π; length = n)
    x = C[1] .+ r*cos.(u) * sin.(v)'
    y = C[2] .+ r*sin.(u) * sin.(v)'
    z = C[3] .+ r*ones(n) * cos.(v)'
    return x, y, z
end

surface(sphere(2, [1,2,3]))

```

---

_[View the full topic](https://discourse.julialang.org/t/plotting-a-sphere-with-inputs-of-radius-and-center/85978)._
