You are here

3-D Rotation Script

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Rate this item!
AttachmentSize
JMS-3DRotImage.scm8.24 KB
Original Grid60.5 KB
Rotated Grid123.38 KB

This script will rotate an existing image about the X, Y and Z axes. It will also include a magnification factor so you can scale your image while rotating.

The inputs are the angles to rotate the image around the X, Y, and Z axes. Some values (usually high X and Y values) will result in a very distorted picture, regardless of what other inputs you have. If you get one of those, just undo and try again. That's just the way math works, folks!

The "Camera Position" controls several things, including how distorted the image will be. The default value gives good results most of the time. Very large values will tend to somewhat smooth out larger rotation angles.

The magnification factor will scale up the area of the image. A 640x480 image with a magnification factor of 1.5x, would have a rotated area of 640x480x1.5 pixels. The canvas itself will be larger than that, as there will be transparent areas around the rotated base image. As you would expect, large values for the magnification factor will result in very large images that will take up lots of memory.

In addition to the script, I've attached a picture of a rendered grid, and the picture of that grid rotated with the default values of the script. When installed, the script will appear in the Filters/SambrookJM menu, but that can be changed by editing the last line of the script to put it wherever you want in your menu hierarchy.

For some more information on what this script does, check out http://en.wikipedia.org/wiki/3D_projection

[Edit] I've added a "(Zero will give you an error. Please do not use that value.)" message on the script window for the camera location, and changed the default camera value to 9.9 to make it more difficult to get to 0 via the arrows.

Code License: 
GIMP Version: 
Scripting Engine: 

Comments

GIMP's Map Object filter (choose the default plane option) should do this and it has a cool preview too. :)

I'd almost always used the Map to Sphere option (see my planet scripts on this site for that) on that menu, and never used the map to plane.

Well, at least this one lets you scale the image at the same time... Other than that, it was good practice for the math that is required for these transformations.

Think I should add the "redundant" tag to the script??

Controlling the Z option will scale the result too, so yes, add it to your redundancy list. lol

edit:

Cool that you are able to figure out another way to do things though. Like how you think. :)

I put 0 for the "Camera Position" and I got the following error:
"Message: Error: /: division by zero "

"Hey, doc. It hurts when I do this."
"Then don't do that!"

:-)

In all seriousness, the script calculates the new location to "see" the rotated image (chosen by your magnification factor) by dividing by the area after the first run through of the script. If your camera position is zero, then the area will be zero, which will result in a divide by zero error.

I should have put a warning about that in the script window. Sorry, but there's not much else that can be done about that.

Same error with your Brick Wall script when you set "color variatons" to zero.
This is on Linux.
Does Windows intercept programs that risk doing division by zero automatically?
Gerard.

I tried with gimp 2.6.11 under windows XP and I had the error.
This is easily corrected, in the Brick Wall script, by changing the lowest value for "Color Variations ". There just has to replace 0 by 1.
It is more difficult for "3-D Rotation Script". Why not put "0 = random" or an option like that?
[edit] you were quicker than me to post

I wish Windows were that efficient, but alas, it's just my sloppy coding. :-(

When did you get the divide by zero error in this script? If it's when you set the camera location to zero, then yes, you will get a division by zero error. (See the above comment.)

I didn't catch the comment in the Brick Wall thread about the color variation being set to zero giving an error...sorry about that. That error was caused something different; GIMP trying to run the command (rand 0) because of the way the variables were calculated. It now does (rand 1) instead, which should result in zero. I fixed that one, and I'll repost the script with the fix. Good catch on that one.

Subscribe to Comments for "3-D Rotation Script"