We are about to switch to a new forum software. Until then we have removed the registration on this forum.

- All Categories 25.7K
- Announcements & Guidelines 13
- Common Questions 30
- Using Processing 22.1K
- Programming Questions 12.2K
- Questions about Code 6.4K
- How To... 4.2K
- Hello Processing 72
- GLSL / Shaders 292
- Library Questions 4K
- Hardware, Integration & Other Languages 2.7K
- Kinect 668
- Arduino 1K
- Raspberry PI 188
- Questions about Modes 2K
- Android Mode 1.3K
- JavaScript Mode 413
- Python Mode 205
- Questions about Tools 100
- Espanol 5
- Developing Processing 548
- Create & Announce Libraries 211
- Create & Announce Modes 19
- Create & Announce Tools 29
- Summer of Code 2018 93
- Rails Girls Summer of Code 2017 3
- Summer of Code 2017 49
- Summer of Code 2016 4
- Summer of Code 2015 40
- Summer of Code 2014 22
- p5.js 1.6K
- p5.js Programming Questions 947
- p5.js Library Questions 315
- p5.js Development Questions 31
- General 1.4K
- Events & Opportunities 289
- General Discussion 365

Hi, I want to rotate many 3D planes around their center along the Y axis. My idea is to translate each plane into the center of the screen, rotate them along Y axis and then translate them to their right place. But after the rotation all the axes are rotated and I cannot figure how to translate the planes correctly. Any idea? Is it possible to remove perspective?

Thanks, paolofuse

Tagged:

## Answers

You didn't mention it, but I'm going to assume that the planes all have their normal pointing along the y-axis. If they don't then after you translate them to the origin you would have to first rotate them to align that way.

Edit: In other words I am assuming that the planes exist on the xz-plane. If they don't they will still spin on the y-axis which will make them look "tilted" while spinningAssuming that their normals point along the y-axis:

- Take each of the 4 corner points, use them to find the plane's center (the average of the 4 point's positions), and translate all 4 to the origin using the plane's center. None of the points will actually be at the origin, the center of the plane will be there

- Rotate all 4 points along the y-axis

- Translate all 4 points back using the plane's center position - Repeat these steps for the other planes

Here is an example in 2D, you could think of it as looking down on the planes from above to relate it to yours:

Tweaked the answer a little in order to understand how it works. But it's beyond me! :(

Anyways, gonna post my exercise anyways as an alternative: ;;)

Hi asimes, what you told in your first pot is correct. I need to rotate along Y axis, so what I need is to TILT my planes. It's easy to do if I translate a plane into the center, but I need to rotate each plane around its Y axis. Thanks.

The same code will produce that effect, I just pointed out that it would happen because I was not sure if it was desirable.

Edit: Normally an additional rotation step is necessary to avoid this effectThe example I posted is in 2D and performs a rotation around the z-axis because we are looking at x and y in 2D. If you were to replace all of the code that affects y with z then it would cause a rotation around the y-axis.

Here, I thought I'd make a 3D version incase my explanation was not clear enough:

@GoToLoop, When a rotation is performed it rotates an object around the origin. If the plane was not translated so that its center was at the origin then it would fly around all over the place.

The first step of the for loop moves the plane so that its center is at the origin (p[i].sub(c)). Then the math for a rotation about the desired axis (the z-axis in the 2D sketch and the y-axis in the 3D sketch). Finally the plane is translated back to where it should be after being rotated (p[i].add(c)).

The problem with doing this using Processing's translate() / rotate() functions is that the coordinate system has changed and so translating the plane back where it belongs after the rotation is not very straightforward.

I have sаme trouble.

I think you have to use beginCamera() and endCamera() function, but I'm not sure... http://www.processing.org/reference/beginCamera_.html

Hi. My friend help me. this is virtual screens