Functions to generate Povray files for the open Raytracer.
The Povray interface of Euler generates Povray files in the home directory of the user, and calls Povray to parse these files. The default file name is current.pov, and the default directory is eulerhome(), usually c:\Users\Username\Euler. Povray generates a PNG file, which can be loaded by Euler into a notebook. To clean up these files, use povclear().
You need to load the Povray commands with "load povray". There is an introduction notebook demonstrating the package.
For more information on the Povray povray project, see
Moreover, you need to install Povray (32bit or 64bit), and put the sub-directory "bin" of Povray into the environment path, or set the variable "defaultpovray" with full path pointing to "pvengine.exe".
The pov3d function is in the same spirit as plot3d. It can generate the graph of a function f(x,y), or a surface with coordinates X,Y,Z in matrices, including optional level lines. This function starts the raytracer automatically, and loads the scene into the Euler notebook.
Besides pov3d(), there are many functions, which generate Povray objects. These functions return strings, containing the Povray code for the objects. To use these functions, start the Povray file with povstart(). Then use writeln(...) to write the objects to the scene file. Finally, end the file with povend(). By default, the raytracer will start, and the PNG will be inserted into the Euler notebook.
The object functions have a parameter called "look", which needs a string with Povray code for the texture and the finish of the object. The function povlook() can be used to produce this string. It has parameters for the color, the transparency, Phong Shading etc.
Note that the Povray universe has another coordinate system. This interface translates all coordinates to the Povray system. So you can keep thinking in the Euler coordinate system with z pointing vertically upwards,a nd x,y,z axes in right hand sense.
For vectors you can always use a instead of [a,a,a], and the vector "povx" is defined as [1,0,0] etc.
function povrgb (c:integer, transparent=0)
Color in rgb for Povray This function returns a string containing a color definition for Povray using "color rgb <r,g,b>". If transparent>0, "rgbf" will be used instead of "rgb". The function works for the 16 Euler colors or colors generated with rgb(r,g,b). See:
povlook (Povray with Euler)
function povxyz ()
povxyz(x,y,z), povxyz(v), povxyz(r) compute coordinates for Povray. This function is used by many of the Povray functions to translate coordinates to a string for Povray. Note that Povray coordinates are different from Euler coordinates. The horizontal plane is x-z in Povray, and x-y in Euler. This function takes care of that transformation. With one real argument a the vector [a,a,a] is used. Also the functions povx, povy, povz can be used for the coordinate axes, and povc for the coordinate center. The functions returns a string. See:
povy (Povray with Euler),
povz (Povray with Euler),
povc (Povray with Euler)
function povx () := [1,0,0]; // x-axis
function povy () := [0,0,1]; // y-axis
function povz () := [0,1,0]; // z-axis
function povc () := [0,0,0]; // center
function writeCamera (aspect:positive number=1, anaglyph=0)
Set the camera for Povray. This function need not be used directly. Use povstart() instead. The function writes the camera position to the output file for Povray. The current view is used to position the camera. To change the view use the view() function, or the zoom(), viewangle(), or viewheight(), viewdistance() service functions. The camera looks at the current center. To change this use the center() function. aspect : The image is assumed to be square. If not, change the aspect. anaglyph : If this is true the scene will be tilted with the default anaglyph separation times the anaglyph value. This is used in pov3d() and povanaglyph(). See:
povstart (Povray with Euler),
pov3d (Povray with Euler),
povanaglyph (Povray with Euler)
function writeAxis (t1:number, t2:number, delta:real vector=none, d:number=0.02, c:integer=gray, axis:integer=1, add:number=0.1)
Axis for Povray Creates an axis in form of an arrow. This functions is used in pov3d to create all three axes. Since pov3d packs the scene into the unit cube, and scales the function, there is a translation vector delta. t1, t2 : left and right end of the axis delta : translate the axis using this vector (in Euler coordinates) d : thickness of the axis c : color of the axis axis : which axis 1=x, 2=y, 4=z add : additional length exceeding t1 an t2 on both sides See:
pov3d (Povray with Euler)
function writeAxes (xmin=-1,xmax=1,ymin=-1,ymax=1,zmin=-1,zmax=1, delta:real vector=none, d:number=0.02, c:integer=gray, add:number=0.1)
Write an axis System. The function expects the start and the end of each axis. For the other parameters see writeAxis(). It writes to the Povray file directly. Example: >povstart(zoom=4,center=[0,0,1/2],height=45?); >writeAxes(-1,1,-1,1,0,1.4,d=0.01); >writeln(povsphere([0,0,1/2],1/2,povlook(green,0.5))); >writeln(povpoint([0,0,1],povlook(gray),size=0.02)); >povend(); See:
writeAxis (Povray with Euler)
function writeGlobal (c:integer=white, gamma=1.4)
Write the global header. This is called automatically with povstart(). Sets the color of the ambient light and the assumed gamma.
function writeBackground (c:integer=white)
Write the background for the scene. This is called automatically with povstart(). Sets the background color.
function writeLight (v:real vector=[2,3,4], c:integer=white, distance=none, shadow=true, fade=0)
Write the light source. This is called automatically with povstart(). The light source is in direction of the vector v. The distance of the light source is the distance in view (which is the distance of the camera). shadow=0 : produces no shadow in the scene.
function povray (filename=none, width:index=450, height:index=450, aspect:positive number=1, exit:integer=true)
Start the Povray process. By default, this is called in povend(). Start the Povray program. The program name is in the global variable "defaultpovray". The default filename current.pov in the user home directory is used if file==none. exit=false allows to keep the Povray window open. Euler will wait, until you close it. filename : The filename to be used (without .pov)
function povopen (filename)
Open the povray file for writing. This is called in povstart(). Do not forget to close it before you use the file. The povend() function closes the file automatically. See:
open (Euler Core)
function povscalexyz (x,y,z)
Scale x,y,z to fit into a unit cube. Return {x,y,z,f,cx,cy,cz} where f is the factor used, and cx,cy,cz is the new center of the coordinate system. See:
pov3d (Povray with Euler)
function povscalef (x,y)
Scale x,y to fit into a unit square. See:
povscalexyz (Povray with Euler)
function povscalez (z)
Scale z to fit into [-1,1]
function povload (file=none, anaglyph=false)
Load the Povray image into the Notebook. By default, this is called in povend(). file : If none, use defaultfile
function povstart (file=none, zoom=none, distance=none, angle=none, height=none, light:real vector=[2,2,4], lightcolor=white, background=white, aspect=1, shadow=true, center=[0,0,0], fade=0, anaglyph=0)
Start a Povray scene. This function opens the file, and sets the scene, including light, camera and background. zoom, distance, angle, height : Change the view locally in this function. The angle is measured from the negative y-axis, as in plot3d() and view(). The height is from the x-y-plane. Both angles are in radians. Use angle=30? to convert. light, lightcolor : A vector to the light source and the color of the light. background : The background color aspect : The aspect ratio of your window. For square images use 1. Note that you need the same aspect in povend(). shadow : A flag for shadows. center : The point, where the camera looks at. The camera itself is determined by the view. fade : If nonzero, fading with this exponential rate is used. The fading distance is the distance from the light to the center. See:
povend (Povray with Euler),
view (Euler Core),
view (Plot Functions),
view (Maxima Documentation)
function povend (file=none, povray=true, w=450, h=450, aspect=1, exit=true, imgload=true)
End a Povray scene Closes the scene file. By default, the Povray process will start, and the image will be loaded into the notebook. w,h,aspect : In combination determine the aspect ratio of your scene. Note that you need the same aspect as in povstart(). exit : If false, the Povray window will not close automatically. imgload : If false, the image will not be loaded. You can then find the image in the Euler subdirectory of your home directory. >povstart(zoom=3.6,aspect=4/3); >writeln(povsphere([0,-1,0],1/2,povlook(gray))); >writeln(povsphere([0,1,0],1/2,povlook(gray))); >writeln(povsphere([0,0,0],1,povlook(green))); >povend(h=300,aspect=4/3); Or, if you want to insert the image later: >povend(h=400,aspect=4/3,<imgload); // make image >loadimg(defaultfile); // manually insert the image See:
povstart (Povray with Euler)
function povanaglyph (scene$:string, file=none, zoom=none, distance=none, angle=none, height=none, light:real vector=[2,2,4], lightcolor=white, background=white, aspect=1, shadow=true, center=[0,0,0], fade=0, w=450, h=450, aspect=1, exit=true, imgload=true)
Create a red/cyan anaglyph Create an anaglyph with a scene, which is generated in the function scene. The Povray command runs twice, and generates two PNG files in the user directory. The parameters combine povstart and povend >function f() ... $ writeAxes(-1,1,-1,1,-1,1); $ writeln(povcylinder([-1,0,0],[1,0,0],1,povlook(lightblue,0.4))); $endfunction >povanaglyph("f"); See:
povstart (Povray with Euler),
povend (Povray with Euler)
function povlook (color=green, transparent=0, ambient=none, phong:real=none, phongsize:real=100, reflection=none, diffuse=none)
Texture and finish of an object. Returns a string containing the Povray code for this texture and finish. color : the color of the object. transparent : If nonzero, the color will be transparent. ambient : The amount of ambient light to be used. phong, phongsize : If nonzero, a shining finish will be used. reflection : Makes the object reflect other objects. >povlook(green) >povlook(gray,0.5) // half transparent See:
rgb (Plot Functions)
function povl () := povlook(args(1));
function writeTriangleMesh (x:real, y:real, z:real, look:string=defaultlook, xv:real=none, yv:real=none, zv:real=none, simple:integer=false)
Mesh object with triangles Write a mesh object for the surface with coordinates x,y,z. The surface is formed of 4 triangles for each rectangular segment, connecting the corner to the average midpoint of the 4 points. The evaluation of x,y,z follows the matrix language of Euler. If normal vectors are present, the functions used two triangles in each matrix element, but adds the vectors to the scene. Note that this function does writeln() to the output file. If you need an object use povtriangles(). See:
povtriangles (Povray with Euler)
function povtriangles (x:real, y:real, z:real, look:string=defaultlook, xv:real=none, yv:real=none, zv:real=none, simple:integer=false, include=false)
A mesh object Mesh objects are formed of hundreds of triangles. They cannot be stored in Euler strings. So this function write either to an include file and returns a #include statement. Or it writes to the scene file, and #declares an object there. Then it returns an object. Usually, it is not necessary to use an include file. For a description of the triangle mesh and the normal vectors, see writeTriangleMesh(). See:
writeTriangleMesh (Povray with Euler)
function povgrid (x:real, y:real, z:real, look:string=defaultlook, d=none, dballs=none, include=false, skip:positive integer vector=none)
A mesh object Grid objects, like mesh objects, are formed of hundreds of triangles. They cannot be stored in Euler strings. So this function write either to an include file and returns a #include statement. Or it writes to the scene file, and #declares an object there. Then it returns an object. Usually, it is not necessary to use an include file. d, dballs : Diameter of grid and balls skip : Scalar or 1x2 vector. Skip rows and columns of the matrix. With this parameter, it is possible to generate a fine grid, but show only a few grid lines. Example: >povstart(center=[0,0,1],zoom=3.5); >x=-1:0.05:1; y=x'; >writeln(povgrid(x,y,x^2+y^2,skip=5,d=0.01,dballs=0.02)); >povend(); See:
povtriangles (Povray with Euler)
function povbox (P1: real vector, P2: real vector, look:string=defaultlook)
A box with these two corners. The box parallel to the axes. If you need rotated box, use an object containing the box, and the rotation parameter. >povstart(); >writeln(povobject(povbox([-1,-1,-1],[1,1,1]),rotate=xrotate(-20?))); >povend();
function povcylinder (P1: real vector, P2: real vector, r: number, look:string=defaultlook, open:integer=false)
A cylinder with these two ends and radius
function povdisc (P: real vector, v: real vector, r:number, d: number=none, look:string=defaultlook)
A disc with center, normal and radius If d==none the disc uses defaultpointsize for its thickness.
function povintersection (v:string vector, look:string=defaultlook)
Intersection of the objects in v v : a vector of string, containing the objects.
function povunion (v:string vector, look:string=defaultlook)
Union of the objects in v v : a vector of strings, containing the objects.
function povmerge (v:string vector, look:string=defaultlook)
Merge of the objects in v Merging removes the inner boundaries v : a vector of strings, containing the objects. See:
povunion (Povray with Euler),
povintersection (Povray with Euler)
function povdifference (v1:string, v2: string, look:string=defaultlook)
v1 minus v2
function povcone (P1: real vector, r1: number, P2: real vector, r2: number, look:string=defaultlook)
A cone with these two ends and radii.
function povsphere (P: real vector, r: number, look:string=defaultlook)
A sphere with midpoint and radius.
function povtext (s:string, P:real vector, look:string=defaultlook, d:number=none, size:number=none, font="timrom.ttf", rotate:number=0°)
Text object at position P d : thickness of the text size : height of the text font : text font name rotate : rotation around vertical axis
function povplane (P: real vector, d: number, look:string=defaultlook, clippedby:string=none)
A plane with a'.v=d, a=[x,y,z]. Note that the plane is really a half space, unless it is clipped. For clipping use any full object.
function povpoint (P: real vector, look:string=defaultlook, size:number=none)
A point The size will be the radius of the sphere. By default it is the defaultpointsize. >povstart(zoom=2,center=[0,0,-1]); >X=randnormal(3,100,0,1/2); >loop 1 to cols(X); writeln(povpoint([X[1,#],X[2,#],X[3,#]],povlook(red))); end; >writeln(povdisc([0,0,-3],[0,0,1],2)); >writeAxis(-3,1,axis=3); >povend();
function povsegment (P1: real vector, P2: real vector, look:string=defaultlook, size=none)
A line segment between the two points
function povarrow (x: real vector, v: real vector, look:string=defaultlook, d:number=none)
An arrow d : The thickness of the arrow. By default, this is the defaultpointsize
function povdefine (a:string, b: string)
Declares an object in Povray Sometimes, you wish to define an object in Povray, not in an Euler string. You can later use the object by name. You can also define other things, like finishes in Povray.
function xrotate (a) := " rotate "+deg(a)+" *x "
function yrotate (a) := " rotate "+deg(a)+" *z "
function zrotate (a) := " rotate "+deg(a)+" *y "
function povobject (object:string, look:string="", translate=none, rotate=none, scale=none)
Povray object containing another object scale : A vector or a scalar to stretch the object. If a vector is used its coordinates are the factors in each of the three directions. rotate : The rotation parameter. This can be a vector, which contains the rotations around the x, y, and z axis in this order. The values must be in radians. Usually, you want to use the functions xrotate(a), yrotate(a), zrotate(a), which return strings. These strings can be concatenated for the rotation parameter. translate : A vector for the translation. Example: >povstart(); >writeAxes(-1,1,-1,1,-1,1); >sph=povsphere([0,0,0],1); >rot=xrotate(10?)+yrotate(45?); >tr=[0,0,-1/2]; >writeln(povobject(sph,scale=[2,1,0.2],rotate=rot,translate=tr)); >povend();
function povsurface (f:string, look:string=defaultlook, container:string=none, maxgradient=5, open=true)
Implicit surface The surface is defined by f(x,y,z)=0. f : Contains the formula f. Povray uses a different syntax for mathematical functions. E.g., pow(x,2) must be used instead of x^2. Please refer to a Povray manual. The file functions.inc is #included in povstart(). maxgradient : If 5 is too low and the surface looks ugly, use a higher value at the cost of increased time. open : If false, the cube will be filled between the surface and the cube. Effectively, the set where the function <=0 will be visible. container : A box containing the surface. Default is povbox(-1,1,""). Example: >povstart(); >writeln(povsurface("pow(x,4)+pow(y,6)+pow(z,2)-1")); >writeAxes(); >povend();
function povclear ()
Remove all temporary Povray files.
function pov3d (x, y=none, z=none, xmin:number=-1, xmax:number=1, ymin:number=-1, ymax:number=1, r:number=none, n:index=40, file=none, axis:integer=7, look:string=none, axiscolor:integer=gray, zoom=none, distance=none, angle=none, height=none, light:real vector=[2,3,4], lightcolor=white, background=white, povray=true, w=450, h=450, shadow=true, center=[0,0,0], fade=0, xv:real=none, yv:real=none, zv:real=none, level:real vector=none, dlevel=0.02, levellook:string=none, add=none, loadimg=true, anaglyph=false, fscale=true, scale=true)
Multi-purpose function to plot 3D in Povray pov3d("f(x,y)") : plots a function pov3d(x,y,z) : plots a surface given by x,y,z xmin,xmax,ymin,ymax : range x and y n : resolution for x and y r : alternatively radius for quadratic or polar plots cx, cy, cz : center for r file : used, if not the defaultfile="current" (without .pov) color : color of the plot axis : 1,2,4 or sum of these for x, y, z axis axiscolor : color of axis zoom, distance, angle, height : see view() light : direction vector to the light source lightcolor : color of the light background : color of the background povray : if true, the Povray program is called w, h : size of png loadimg : if false, the image is not loaded into the notebook. add : one Povray object to add >pov3d("x^3+y^2",angle=-80?, ... > level=-2:0.2:2,dlevel=0.01,levellook=povlook(red), ... > add=povtext("z=x^3+y^2",[0,-0.2,1.2],size=0.06,rotate=-90°), ... > zoom=4); See:
view (Euler Core),
view (Plot Functions),
view (Maxima Documentation)