# \[REPORTED\] PMatrix3D cannot be cast to PMatrix2D

**URL:** <https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779>\
**Category:** Processing\
**Created:** [January 24, 2019, 2:45am UTC](https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779 "2019-01-24T02:45:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)\
**Post date:** [January 24, 2019, 2:45am UTC](https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779/1 "2019-01-24T02:45:06Z")

</div>

Hello forum

I’ve run into an unexpected exception while trying to rotate a PShape in the Z axis, even though it works fine in the X and Y axis. Has anyone else gotten this problem? It only started happening after installing 3.5 (3.5.1 and 3.5.2)

I believe this code used to work fine

```auto
PShape shape;
void setup(){
size(500,500,P3D);
shape = createShape(SPHERE,50);
}
void draw(){
 background(100);
 fill(255);
 noStroke();
 shape.rotateX(.2);
 println("success X");
 shape.rotateY(.2);
 println("success Y");
 shape.rotateZ(.2);
 println("success Z");
 translate(width/2.0,height/2.0);
 shape(shape);
}

```

the exception:

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

---

<div class="post-metadata">

**Author:** ![JackWitherell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jackwitherell/32/3361_2.png) [@JackWitherell](https://discourse.processing.org/u/JackWitherell)\
**Post date:** [January 24, 2019, 10:34am UTC](https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779/2 "2019-01-24T10:34:21Z")

</div>

Oddly enough, I ran another sketch and used rotateZ by itself and it works fine, the behavior seems to be limited to PShape’s rotateZ function…

Seems like a nasty bug that should be reported to github!

---

<div class="post-metadata">

**Author:** ![BennyHacker](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bennyhacker/32/2969_2.png) [@BennyHacker](https://discourse.processing.org/u/BennyHacker)\
**Post date:** [January 24, 2019, 4:50pm UTC](https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779/3 "2019-01-24T16:50:00Z")

</div>

I’ve reported it: [https://github.com/processing/processing/issues/5770](https://github.com/processing/processing/issues/5770)

---

<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:** [June 18, 2019, 4:21pm UTC](https://discourse.processing.org/t/reported-pmatrix3d-cannot-be-cast-to-pmatrix2d/7779/4 "2019-06-18T16:21:31Z")

</div>

I ran into this issue as well with some old code (see last post):  
[PShape rotations and translations…](https://forum.processing.org/two/discussion/comment/119164/#Comment_119164)

Workaround for P3D:

```auto
// s2.rotate(heading); // Generates error in Processing 3.5.3   
  s2.rotate(heading, 0, 0, 1); // Workaround for P3D

```

I also tried P2D and some rotations were not correct for PShapes.  
Workaround for P2D:

```auto
  s2.translate(-10, -10);    
  s2.rotate(heading);   
  shape(s2, v1.x, v1.y); 
// s2.resetMatrix(); // Shapes no longer rotating correctly!
  s2.rotate(-heading); // Workaround for P2D Rotated back...
  s2.translate(10, 10); // Workaround for P2D Translated back..

```

Also box() in P2D did not display with console message “box() is not available with this renderer.”  
Fix:

```auto
// box(20, 20, 0); // Does not display in P2D with console message 
rect(-10, -10, 20, 20); // Works in P2D!

```

🙂
