# Full rotation using pointLight();

**URL:** <https://discourse.processing.org/t/full-rotation-using-pointlight/32185>\
**Category:** Coding Questions\
**Created:** [September 10, 2021, 8:41pm UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185 "2021-09-10T20:41:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![achip30](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@achip30](https://discourse.processing.org/u/achip30)\
**Post date:** [September 10, 2021, 8:41pm UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185/1 "2021-09-10T20:41:18Z")

</div>

Hello, my brain hurts. I am using the pointLight method on this sphere. I want the light to rotate around the sphere, but I can’t figure out how to do a complete rotation. I am incrementing the z position, but it stops when it gets to the middle of the sphere (max z). Any pointers on how I can get this to have a seemingly full rotation around the sphere? I’m thinking that I have to incorporate the x or y positions of the light, but I’m struggling to figure it out. Thanks in advance.

```auto
const ballcolor = [30, 180, 255]; // COLOR TO CHANGE (H, S, B)
let brightness = 40;
let z = -40;

function setup() {
   createCanvas(400, 400, WEBGL);
   colorMode(HSB,255);
   frameRate(10);
}

function draw() {

  background(30,20,brightness);
  brightness += 5;
  if (brightness >= 161) brightness = 70;
  
  // CENTRAL SPHERE 
  push();
  noStroke();
  
  //HELP
  z += 20;
  if (z >= 800) z = -40;
  pointLight(ballcolor, 200, -200, z);  
  
  specularMaterial(250);
  shininess(70);
  sphere(75);
  pop();
}

```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [September 10, 2021, 10:54pm UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185/2 "2021-09-10T22:54:52Z")

</div>

Hi @achip30,

> [@achip30](#):
>
> I want the light to rotate around the sphere, but I can’t figure out how to do a complete rotation.

What you want is simple trigonometry:

> **[Trigonometry](https://en.wikipedia.org/wiki/Trigonometry)**
>
> Trigonometry (from Ancient Greek τρίγωνον (trígōnon) 'triangle', and μέτρον (métron) 'measure') is a branch of mathematics concerned with relationships between angles and ratios of lengths. The field emerged in the Hellenistic world during the 3rd century BC from applications of geometry to astronomical studies. The Greeks focused on the calculation of chords, while mathematicians in India created the earliest-known tables of values for trigonometric ratios (also called trigonometric fun Thr...

Try to think about how you would compute the position of a point at a certain radius on a circle centered on another point in space. ([hint](https://stackoverflow.com/questions/5300938/calculating-the-position-of-points-in-a-circle))

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 11, 2021, 6:20pm UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185/4 "2021-09-11T18:20:17Z")

</div>

you want cos and sin to make a circle from an angle going from 0…360

(multiply with radius (200?) and add centerx and centery)

the circle you get:

- your x is your x and
- your y is your z

```auto
float x = cos (radians(angle)) * radius + centerX; 
float z = sin (radians(angle)) * radius + centerY;

```

see [Download GitHub directory](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2Fprocessing%2Fprocessing-docs%2Ftree%2F125b9452d01b961e2bdfff90cd016fb1f2a37006%2Fcontent%2Fstatic%2Ftutorials%2Ftrig)

---

<div class="post-metadata">

**Author:** ![achip30](https://avatars.discourse-cdn.com/v4/letter/a/e56c9b/32.png) [@achip30](https://discourse.processing.org/u/achip30)\
**Post date:** [September 11, 2021, 11:43pm UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185/5 "2021-09-11T23:43:37Z")

</div>

Helped a lot, thanks @Chrisir and @josephh.  
Updated code:

```auto
const ballcolor = [30, 180, 255]; // COLOR TO CHANGE (H, S, B)
let brightness = 40;

//let y = -200;
let rad = -10;
function setup() {
   createCanvas(400, 400, WEBGL);
   colorMode(HSB,255);
   frameRate(10);
}

function draw() {
  background(20);
  /*background(30,20,brightness);
  brightness += 5;
  if (brightness >= 161) brightness = 70;*/
  
  // CENTRAL SPHERE 
  push();
  noStroke();
  rad += 10; 
   var x = (cos(radians(rad)) * 200);  
   var z = (sin(radians(rad)) * 200); 
   var y = (cos(radians(rad)) * 200);
  pointLight(ballcolor, x, -y, z); 
  specularMaterial(250);
  shininess(100);
  sphere(75);
  pop();
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [September 12, 2021, 12:04am UTC](https://discourse.processing.org/t/full-rotation-using-pointlight/32185/6 "2021-09-12T00:04:27Z")

</div>

Hello,

This may be of interest:

> **[Spherical coordinate system](https://en.wikipedia.org/wiki/Spherical_coordinate_system)**
>
> In mathematics, a spherical coordinate system is a coordinate system for three-dimensional space where the position of a point is specified by three numbers: the radial distance of that point from a fixed origin, its polar angle measured from a fixed zenith direction, and the azimuthal angle of its orthogonal projection on a reference plane that passes through the origin and is orthogonal to the zenith, measured from a fixed reference direction on that plane. It can be seen as the three-dimensi...

I used the Cartesian coordinates (x, y, z) directly and stepped through Φ phi and θ theta over time.

From Wikipedia page above:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/097c1ad28f66212b6f89dd5753d2cd02be5b09ef.png)

A link to Trigonometry tutorial:

> **[Trigonometry Primer](https://processing.org/tutorials/trig/)**
>
> An introduction to trigonometry.

Does not seem to be in the tutorials on new site.

Have fun!

`:)`
