# How to make a continuous graph in 3D under an iterative process?

I'm solving a problem in which I have to plot a series of image points $P'$ from a set of points $P$ that lies 5 cm away from a sphere with radius 2 cm, in such a way that all $P'$ lies inside the sphere.

My problem lies that as a beginner in Mathematica I don't know how to use the command While in order to make a final graph in 3D with those image points.

For the moment I'm testing with this code, but surely there's something wrong:

y = 5
n = 0
While[n < y, Print[n]; n = n + 0.5]
While[n < y,
Show[Graphics3D[{PointSize[0.1],
Point[{n, 0, 0}, VertexColors -> {Green}]}]]; n++]

• There appear to be multiple issues with your code. (e.g. the second loop is never executed since n=y after the first one). Try to look at the documentation and its many examples for the functions you are using, e.g. Graphics3D. Then you can ask specific questions if you still have problems. Also, Mathematica uses a mainly functional programming style, where you normally don't need explicit loops (You can look at other questions on this site, and the documentation page about Functional programming for a start). Commented Aug 22, 2017 at 8:17
• Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basic rules of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. Your question has been answered, but its a good idea to wait 24hours for other answers before accepting the best one for you. Commented Aug 23, 2017 at 9:43

You are trying to program in a style that doesn't come natural in Wolfram Language. Your code in Mathematica style should look like this.

Graphics3D[
{
PointSize[0.1]
, Table[
Point[{n, 0, 0}, VertexColors -> {Green}]
, {n, 0, 5, 0.5}
]
}
]


Now if you want to plot many Point outside a Sphere you can do something like this:

Graphics3D[
{
Opacity[0.3]
, Red
, Sphere[{1, 1, 1}, 2]
, Green
, Table[
Point[RandomReal[{2, 4}, 3]]
, {n, 1000}
]
}
]


Code and plots on Mathemathica v 11.1.1