# Rotate vectors in 3D

**URL:** <https://discourse.processing.org/t/rotate-vectors-in-3d/18660>\
**Category:** Coding Questions\
**Created:** [March 14, 2020, 6:08pm UTC](https://discourse.processing.org/t/rotate-vectors-in-3d/18660 "2020-03-14T18:08:42Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![OrSarfati](https://avatars.discourse-cdn.com/v4/letter/o/43a26b/32.png) [@OrSarfati](https://discourse.processing.org/u/OrSarfati)\
**Post date:** [March 14, 2020, 6:08pm UTC](https://discourse.processing.org/t/rotate-vectors-in-3d/18660/1 "2020-03-14T18:08:42Z")

</div>

Hi there!

I did some research about this topic on this forum and in general. The subject was discussed here before but with no-code solutions for **3D**. I like to address that topic again with the hope to find an easy solution that can help me and the following to come.

Let’s say I like to create a Box between two 3D vectors, therefore i have to rotate it according to the angle between V1 to V2. This thread has the same issue in 2D - [WEBGL cylinder between two points](https://discourse.processing.org/t/webgl-cylinder-between-two-points/13806).  
Following that i manage to rotate the **XY** positions accordingly, but still not for **Z**.

**XY rotations are correct, still missing Z rotation.**

 ![DawnSystem_871772](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/36215f6305a2100171b47bd8e09b59d4dba19555.jpeg)

**current use:**

```auto
				PVector heading = new PVector(position2.x - position.x, position2.y - position.y,
						position2.z - position.z);
				PVector midpoint = PVector.lerp(position, position2, 0.5f);

				canvas.strokeWeight(2);
				canvas.noFill();
				canvas.stroke(0, 255, 0);
				canvas.line(p1.pos.x, p1.pos.y, p1.pos.z, p2.pos.x, p2.pos.y, p2.pos.z);

				canvas.stroke(255);
				canvas.pushMatrix();

				canvas.translate(midpoint.x, midpoint.y, midpoint.z);
				canvas.rotate(heading.heading() + PApplet.PI / 1.0f);
				canvas.box(heading.mag(), 5, 5);
				canvas.popMatrix();

```

I was also trying to play with **getRotatedAroundAxis** of Toxiclibs.

As noted - Any pointers will be greatly appreciated 😉  
Thanks!

---

_[View the full topic](https://discourse.processing.org/t/rotate-vectors-in-3d/18660)._
