# PShape.rotateZ() bug?

**URL:** <https://discourse.processing.org/t/pshape-rotatez-bug/17509>\
**Category:** Coding Questions\
**Created:** [February 2, 2020, 4:49am UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509 "2020-02-02T04:49:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Mortimer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Tim\_Mortimer](https://discourse.processing.org/u/Tim_Mortimer)\
**Post date:** [February 2, 2020, 4:49am UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/1 "2020-02-02T04:49:55Z")

</div>

Hi.

New to Processing & this forum.

Been playing with the former about a week or so, really loving it.

Loving the video tutorials & OpenProcessing site: between these 2 resources & the Coding Train channel on Youtube, making solid progress …

I started playing with 3D a few hours ago, & i think i have found a bug.

I was attempting to try & ‘fork’ my cobbled together particle system example (made using the Nature of Code book …) to work in 3D space, hence utilising PShape for my base object & attempting to spray a few around the canvas.

I was successfully able to myShape.rotateX() & myShape.rotateY(), but myShape.rotateZ() yields the following error …

**ClassCastException: processing.core.PMatrix3D cannot be cast to processing.core.PMatrix2D**

i have copied the code below. I hope i have formatted it correctly for display in the forum.

If i am doing something silly here, i welcome the solution. But based on the message, & the fact that rotateX & rotateY behave as expected, i suspect there is an issue here that requires resolution.

Thanks in advance & i hope to continue making progress with Processing going forward, as far as time & my ambitions permit at least

& I hope i have formatted this post correctly with respect to the coding example …

Tim.

```auto
ArrayList<Particle> particles;
 
void setup() {
  size(640,640,P3D);
  particles = new ArrayList<Particle>();
}
 
void draw() {
  
  background(255);
  
  // LIGHTING MUST PRECEDE SHAPE DRAWING
  
  //ambientLight(32,32,32);
  directionalLight(0, 128, 0, 0.9,-0.9, 0.9);
  directionalLight(0, 0, 128, 0.5, 0.25, -0.5);
  
  //lights();
  
  //frameRate(16);
  
  if (frameCount % 24 == 0) {
    particles.add(new Particle(new PVector(random(0,width),random(0,height),random(-200,0))));
  }
  
  for (int i = particles.size()-1; i >= 0; i--) {
    Particle p = (Particle) particles.get(i);
    p.run();
    if (p.isDead()) {
      particles.remove(i);
    }
  }
 
}

class Particle {
  
  PShape s;
  PVector location;
  PVector velocity;
  PVector acceleration;
  float lifespan;
  float rot;
  int dim = 150;
  int dir = 1;
  
  Particle(PVector l) {

     velocity = new PVector(random(-1,1),random(-1,1),random(-1,1));
    location = l.copy();
// 0.0? it's OK, see below ...
    lifespan = 0.0;
    rot = random(-0.01,0.01);
  
    s = createShape();
    s.beginShape();
   s.fill(255);
   s.noStroke();
   
   
   float c =random(4,7);
   for (int i = 0; i < c; i++) {
     s.curveVertex(random(-dim,dim),random(-dim,+dim),random(-dim,0));
   }
   
   s.endShape(CLOSE);
   
  }
 
  void update() {
    
    location.add(velocity);
    if (dir == 1) {lifespan += 0.8;}
    if (lifespan > 250) {dir = -1;}
   
  }
 
  void display() {
    
    
    s.setFill(color(255,lifespan));
    //s.setStroke(color(255,lifespan));
    
    pushMatrix();
    
    // ********BUG ??******** 
    s.rotateZ(rot);
    translate(location.x,location.y,location.z);
    shape(s);
    
    popMatrix();
    
  }

void run() {
    update();
    display();
  }
  
 boolean isDead() {
    if (lifespan < 0.0) {
      return true;
    } else {
      return false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![BrokenCode](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@BrokenCode](https://discourse.processing.org/u/BrokenCode)\
**Post date:** [February 2, 2020, 10:13am UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/2 "2020-02-02T10:13:39Z")

</div>

Hey @Tim_Mortimer!  
I tried to run the sketch and I didn’t see any error!  
I run it on Processing 3.4, Windows 10

---

<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:** [February 2, 2020, 11:43am UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/3 "2020-02-02T11:43:41Z")

</div>

Hello,

Welcome to the Processing forum.

There is a rotateZ() bug in versions 3.5.\*

It is fixed in the 4.0 alpha 1 Pre-Release.

Workaround:

```auto
    // ********BUG ??******** 
    //s.rotateZ(rot); // Bug
    s.rotate(rot, 0, 0, 1); // Rotates about z-axis
    translate(location.x,location.y,location.z);
    shape(s);

```

References:  
[Cannot run rotateZ() within the PShape class #5770](https://github.com/processing/processing/issues/5770)

[https://discourse.processing.org/t/rotate-function-with-4-arguments/5652](https://discourse.processing.org/t/rotate-function-with-4-arguments/5652)

[http://processing.github.io/processing-javadocs/core/](http://processing.github.io/processing-javadocs/core/) has some references:  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3819b55a10fa951f9e76b09473c505da27402382.png)  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/522dbb3e9c837a5e7c768c4b9c2b97882a5f39d0.png)

‘🙂’

---

<div class="post-metadata">

**Author:** ![Tim\_Mortimer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Tim\_Mortimer](https://discourse.processing.org/u/Tim_Mortimer)\
**Post date:** [February 2, 2020, 8:49pm UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/4 "2020-02-02T20:49:52Z")

</div>

great thanks (to you both).

i did search this forum for rotateZ() but didn’t see anything. (the online forum ‘UI’ almost feels a bit overcooked in terms of display of links & references for me … it breaks the continuity a bit, but i’m sure i’ll get used to it …)

(I’m on OSX 10.11 & Processing 3.5.4 incidentally … )

---

<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:** [February 2, 2020, 9:08pm UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/5 "2020-02-02T21:08:04Z")

</div>

> [@Tim\_Mortimer](#):
>
> the online forum ‘UI’ almost feels a bit overcooked in terms of display of links & references for me

I agree in part and cleaned my post up a bit… 🙂

I like references so I can explore the sources of information; I did a lot of exploration into this and shared what I found.

I did make the links “just links” and not a window into the site; this shows up automatically with some links. It also takes more effort to do this.

I am getting into the habit of posting references at the bottom.

References:  
The [source code for Processing](https://github.com/processing/processing) is full of references to rotate for the ambitious to explore.

---

<div class="post-metadata">

**Author:** ![Tim\_Mortimer](https://avatars.discourse-cdn.com/v4/letter/t/ecd19e/32.png) [@Tim\_Mortimer](https://discourse.processing.org/u/Tim_Mortimer)\
**Post date:** [February 2, 2020, 9:27pm UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/6 "2020-02-02T21:27:41Z")

</div>

thanks GLV.

i certainly wasn’t remarking on your reply, which was very much appreciated, orderly & to the point.

Just simply that in attempting to find the details through a quick independent search i wasn’t able to find the same info.

But hey, i’m new here … 😀

---

<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:** [February 2, 2020, 9:36pm UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/7 "2020-02-02T21:36:42Z")

</div>

> [@Tim\_Mortimer](#):
>
> i certainly wasn’t remarking on your reply, which was very much appreciated, orderly & to the point.

Your feedback was an encouragement to clean up my own posts and taken positively; it also reflected what I see at times here in the forums.

I appreciated the “orderly & to the point”.

’ 🙂 ’

---

<div class="post-metadata">

**Author:** ![evilome](https://avatars.discourse-cdn.com/v4/letter/e/e56c9b/32.png) [@evilome](https://discourse.processing.org/u/evilome)\
**Post date:** [June 22, 2020, 8:14pm UTC](https://discourse.processing.org/t/pshape-rotatez-bug/17509/8 "2020-06-22T20:14:54Z")

</div>

Hi,  
I am also new to the forum and have little knowledge of Processing with a similar problem.  
I have a program I took from Instructables that loads a .txt that contains the XYZ coordinates representing the length, the bend angle and the rotation angle which shows interactive 3D visualization and sends as commands to the Arduino to move a 3D wire bender .  
In 2D, everything is going well, but the 3D visualizations have cluttered dots and the machine follows.  
Can anyone take a look at this?  
I will send a link with the videos and the sketch.

[https://drive.google.com/drive/folders/1-VvIdpDYNPRsH2V-9pQqGBzdetRUhO7M](https://drive.google.com/drive/folders/1-VvIdpDYNPRsH2V-9pQqGBzdetRUhO7M)  
Thanks.
