Image:Mug and Torus morph.gif

From Wikipedia, the free encyclopedia

Wikimedia Commons logo This is a file from the Wikimedia Commons. The description on its description page there is shown below.
Commons is a freely licensed media file repository. You can help.
Featured picture This is a featured picture on English Wikipedia and is considered one of the finest images.
  • If you think this file should be featured on Wikimedia Commons as well, feel free to nominate it.
  • If you have an image of similar quality that can be published under a suitable copyright license, be sure to upload it, tag it, and nominate it.
Wikimedia

Contents

Summary

A coffee mug morphing into a torus, a popular example in topology.

Rendered using POV-Ray.

POV-Ray source code

/* 
Torus to mug morphing animation, by Lucas V. Barbosa - January 17, 2007 - Coded in: POV-Ray 3.6
License: Public Domain


Info
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Author user page: http://en.wikipedia.org/wiki/User:Kieff
The final animation at Wikimedia Commons: http://commons.wikimedia.org/wiki/Image:Mug_and_Torus_morph.gif


Notes
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Several modifications were done for each part of the animation and I didn't keep them all here.
So if you wish to reproduce the animation, you'll have to play with this code quite a bit. :)

*/


background { color rgb 1 }

global_settings { assumed_gamma 1.5 }

camera {
        orthographic
        location <0,4,-5>*0.8
        look_at <0,0,0>
        //rotate -45*y
}

#declare dist = 0.2;
light_source {
        <0,0,0>, 1
        //translate <-3,5,-5>*1
        translate 5*y
        translate -5*z
        translate 2*x
}


#declare a = 1;

// Cylinders for the mug shape
#declare C_a = function { pow(x / a,2) + pow(z / a,2)-1.5 }
#declare C_b = function { pow(x / a,2) + pow(z / a,2)-1.2 }
#declare B_b = function { (y+1.3) }


// Torus (handle and the morphing target)
#declare R = 1; #declare r = 0.22;
#declare T_a = function { pow(R - sqrt(pow(x,2) + pow(y,2)),2) + pow(z,2) - pow(r,2) }
#declare R2 = 1; #declare r2 = 0.5;
#declare T_b = function { pow(R2 - sqrt(pow(x,2) + pow(y,2)),2) + pow(z,2) - pow(r2,2) }

// Hollow mug (concave)
#declare Mug = function { min(min(max(C_a(x,y,z),B_b(x,y,z)),max(C_a(x,y,z),-C_b(x,y,z))),max(T_a(x-1,y,z),-C_a(x,y,z))) }

// Solid mug (cylinder with handle, convex)
#declare Mug2 = function { min(C_a(x,y,z),max(T_a(x-1,y,z),-C_a(x,y,z))) }


#declare c = 0.5;

// Linear to smooth interpolation
#declare Int = pow(sin(clock*pi/2),2);


// Functions for the mug parts, left as backups.
// max(C_a(x,y,z),B_b(x,y,z)) bottom
// max(C_a(x,y,z),-C_b(x,y,z)) sides
// min(max(C_a(x,y,z),B_b(x,y,z)),max(C_a(x,y,z),-C_b(x,y,z))) bottom+sides
// max(T_a(x-1,y,z),-C_a(x,y,z)) handle
// min(min(max(C_a(x,y,z),B_b(x,y,z)),max(C_a(x,y,z),-C_b(x,y,z))),max(T_a(x-1,y,z),-C_a(x,y,z))) full mug
        

// Render as isosurface or CSG.
// Isosurface is used in the transitional states.
#declare RenderIsosurface = 0;
#if (RenderIsosurface)
union {
        isosurface {
                function {
                        // Add previously defined object functions using Int and (1-Int) as to generate the smooth transition
                //Mug2(x,y,z)*(1-Int) +
                        Mug(x,y,z)
                        //T_b(x-1,y,z)*Int
                }
                contained_by { box { -<3,1.5,3>, <3,1.5,3> } }
                accuracy 0.001
                max_gradient 5 // 10
                //rotate -90*x
        }
        cylinder {
                <0,-1.3+Int*2.8,0>, <0,-1.5,0>, sqrt(1.5)
        }
        pigment {
                color rgb <0.6,0.8,1> transmit 0.1
        }
        finish {
                specular 0.5
                roughness 0.01
                ambient 0.2
        }
}
#else
union {
        difference {
                cylinder {
                        -1.5*y, 1.5*y, sqrt(1.5)
                }
                cylinder {
                        -2*y, 2*y, sqrt(1.2)
                }
        }
        difference {
                torus {
                        R, r
                        rotate 90*x
                        translate x
                }
                cylinder {
                        -1.5*y, 1.5*y, sqrt(1.5)
                }
        }
        cylinder {
                <0,0-0.25+Int*(1.5+0.25),0>, <0,-1.5,0>, sqrt(1.5)
        }
        pigment {
                colour rgb <0.6,0.8,1> transmit 0.1
        }
        finish {
                specular 0.5
                roughness 0.01
                ambient 0.2
        }
}
#end

/* END OF FILE */

Updated January 12, 2007

  1. New colors: blue hue, brighter, softer shadows
  2. Changed light angle
  3. Non-linear interpolation: looks smoother and less boring
  4. Faster frame rate
  5. Cropped to relevant area
  6. Overall, smaller size for a better-looking image.

Updated January 20, 2007

  1. Removed dithering. Image now has visible colour bands, but at least thumbnails won't look excessively grainy.

Updated March 1, 2007

  1. More saturation of colors

Licensing

Public domain
I, the copyright holder of this work, hereby release it into the public domain. This applies worldwide.

In case this is not legally possible:
I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law.


Afrikaans | Alemannisch | Aragonés | العربية | Asturianu | Български | Català | Cebuano | Česky | Cymraeg | Dansk | Deutsch | Eʋegbe | Ελληνικά | English | Español | Esperanto | Euskara | Estremeñu | فارسی | Français | Galego | 한국어 | हिन्दी | Hrvatski | Ido | Bahasa Indonesia | Íslenska | Italiano | עברית | Kurdî / كوردی | Latina | Lietuvių | Latviešu | Magyar | Македонски | Bahasa Melayu | Nederlands | ‪Norsk (bokmål)‬ | ‪Norsk (nynorsk)‬ | 日本語 | Polski | Português | Ripoarisch | Română | Русский | Shqip | Slovenčina | Slovenščina | Српски / Srpski | Suomi | Svenska | ไทย | Tagalog | Türkçe | Українська | Tiếng Việt | Walon | ‪中文(简体)‬ | ‪中文(繁體)‬ | zh-yue-hant | +/-

See also

File history

Click on a date/time to view the file as it appeared at that time.

Date/Time Thumbnail Dimensions User Comment
current 00:56, 2 March 2007 Thumbnail for version as of 00:56, 2 March 2007 240×240 (497 KB) Kieff (back to old cropping - looks a lot better)
00:49, 2 March 2007 Thumbnail for version as of 00:49, 2 March 2007 189×240 (477 KB) Kieff (more saturation of colors)
08:30, 20 January 2007 Thumbnail for version as of 08:30, 20 January 2007 240×240 (465 KB) Kieff (Removed dithering since it was causing excessive grainy-ness in thumbnails. Image now has colour bands, but at least thumbnails won't look bad.)
05:49, 12 January 2007 Thumbnail for version as of 05:49, 12 January 2007 240×240 (497 KB) Kieff (Better version -- bright color+softer shadows+colour=blue instead of an ugly yellowish-brown --- non-linear interpolation (looks a lot smoother) --- cropped to relevant area -- all in all, looks better and the file is a hundred kilobytes smaller :))
06:02, 2 October 2006 Thumbnail for version as of 06:02, 2 October 2006 320×240 (554 KB) Kieff (A coffee w:mug morphing into a w:torus.)
The following pages on Schools Wikipedia link to this image (list may be incomplete):
The Schools Wikipedia is sponsored by SOS Children , and consists of a hand selection from the English Wikipedia articles with only minor deletions (see www.wikipedia.org for details of authors and sources). See also our Disclaimer.