# How do I write a formula that rotates a point around the coordination systems center?

**URL:** <https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591>\
**Category:** Coding Questions\
**Created:** [December 31, 2023, 5:03pm UTC](https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591 "2023-12-31T17:03:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erik](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@Erik](https://discourse.processing.org/u/Erik)\
**Post date:** [December 31, 2023, 5:03pm UTC](https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591/1 "2023-12-31T17:03:01Z")

</div>

I have a 3D coordination system where x, y, and z dimensions span from 0 to 1000. I have a point randomly placed within these coordinates, and want it to rotate around the center (x, y and z = 500) by a given angle. I want to recalculate the point coordinates instead of relying on the translate(), or rotateX()/rotateY()/rotateZ() methods.

What is the mathematical formula for each of the x, y, and z coordinates? How can i express the formulas in code? (The searches I’ve done doesn’t come up with answers specific to my case).

---

<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:** [December 31, 2023, 5:23pm UTC](https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591/2 "2023-12-31T17:23:05Z")

</div>

Hello @Erik,

Some references to peruse:

> **[Tutorials](https://processing.org/tutorials/)**
>
> Links to videos that cover the Processing basics.

> **[3D Transformations in Processing](https://behreajj.medium.com/3d-transformations-in-processing-de11acdd1fbc)**
>
> This tutorial explores how translation, rotation and scale — taken together under the umbrella term affine transformations — work in…

> **[3D Rotations in Processing (Vectors, Matrices, Quaternions)](https://behreajj.medium.com/3d-rotations-in-processing-vectors-matrices-quaternions-10e2fed5f0a3)**
>
> This tutorial introduces how to rotate objects in 3D beyond Euler angles; to do this, it looks at the basics of matrices and quaternions…

> **[Mathematics and Computing - Martin Baker](https://www.euclideanspace.com/)**
>
> This site looks at mathematics and how it can be computed. The name of the site 'EuclideanSpace' seems appropriate since Euclid made one of the first attempts to document and classify the mathematics known at the time. We now know, through the...

Also numerous Wikipedia topics on this:  
_[wikipedia rotation - Google Search](https://www.google.com/search?q=wikipedia+rotation)_  
Every topic has an _also_ section to explore.

I was on the same adventure years ago exploring transformations… have fun! The adventure continues…

You need to rotate about an axis or a line.

This may be of interest _as a starting point_ if you are rotating about one the x, y or z axes:

> **[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 given point in space is specified by three numbers, (r, θ, φ): the radial distance of the radial line r connecting the point to the fixed point of origin (which is located on a fixed polar axis, or zenith direction axis, or z-axis); the polar angle θ of the radial line r; and the azimuthal angle φ of the radial line r.
> The polar angle θ is measured between the z-axis and ...

I have a strong foundation in mathematics (which helps) and I can adapt what I find in the resources provided. It can certainly be a challenge.

There used to be a tutorial in trigonometry but link is now dead.  
You can find these old tutorials (including trigonometry) here:  
_[processing-docs/content/static/tutorials at master · processing/processing-docs · GitHub](https://github.com/processing/processing-docs/tree/master/content/static/tutorials)_  
You will have to download to view as a web page.

`:)`

---

<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:** [December 31, 2023, 5:34pm UTC](https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591/3 "2023-12-31T17:34:23Z")

</div>

See also [What's the equivalent of using cos() and sin() to find points on the edge of a circle to find points on a sphere? - #5 by KumuPaul](https://discourse.processing.org/t/whats-the-equivalent-of-using-cos-and-sin-to-find-points-on-the-edge-of-a-circle-to-find-points-on-a-sphere/31407/5)

---

<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:** [January 1, 2024, 12:45am UTC](https://discourse.processing.org/t/how-do-i-write-a-formula-that-rotates-a-point-around-the-coordination-systems-center/43591/4 "2024-01-01T00:45:09Z")

</div>

> [@Erik](#):
>
> I want to recalculate the point coordinates instead of relying on the translate(), or rotateX()/rotateY()/rotateZ() methods

This is certainly a good way to learn.

Do you have other reasons to avoid them?

If so:  
When you use translate and rotate, you can still retrieve the resulting position by modelX, modelY and modelZ, check reference.

Happy new year!

Chrisir
