Parametric Functions (C Source)
Function 1 (Circle)
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float pi = 3.1415926, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 3);
titlin ("[sin (u) * cos (v), sin (u) * sin (v), cos (u)]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-1., 1., -1., 1., -1., 1., -1., 1., -1., 1., -1., 1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
surclr (254, 100);
survis ("both");
shdmod ("off", "zscale");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = pi / 30.;
surfcp (zfun, 0., pi, step, 0., 2 * pi - 0.5, step);
disfin ();
}
float zfun (float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = sin (u) * cos (v);
else if (iopt == 2)
w = sin (u) * sin (v);
else
w = cos (u);
return (float) w;
}
Function 2 (Torus)
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float pi = 3.1415926, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 2);
titlin ("[cos (u) * (3 + cos (v)), sin (u) * (3 + cos (v)),", 3);
titlin (" sin (v)]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-3., 3., -3., 1., -3., 3., -3., 1., -3., 3., -3., 1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
surclr (254, 100);
survis ("both");
shdmod ("off", "zscale");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = pi / 30;
surfcp (zfun, 0., 2 * pi - 0.5, step, -pi, pi, step);
disfin ();
}
float zfun (float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = cos (u) * (3.0 + cos (v));
else if (iopt == 2)
w = sin (u) * (3.0 + cos (v));
else
w = sin (v);
return (float) w;
}
Function 3
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.14159, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
mixalf ();
newmix ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function",2);
titlin ("[1.2^v%*sin(u)^2%*sin(v), 1.2^v%*sin(u)^2%*cos(v), ", 3);
titlin ("1.2^v%*sin(u)*cos(u)]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-3.,3.,-3.,1.,-3.,3.,-3.,1.,-2.,2.,-2.,1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("smooth", "surface");
step = p/30.;
tr3shf (-1., 0., 0.);
tr3rot (0., 0., 30.);
surfcp (zfun, 0., p, step, -p/4, 5*p/2, step);
disfin ();
}
float zfun(float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = pow (1.2, v) * (sin(u) * sin(u) * sin(v));
else if (iopt == 2)
w = pow (1.2, v) * (sin(u) * sin(u) * cos(v));
else
w = pow (1.2, v) * (sin(u) * cos(u));
return (float) w;
}
Function 4
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.14159, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
mixalf ();
newmix ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function",2);
titlin ("[1.2^v%*sin(u)^2%*sin(v), 1.2^v%*sin(u)^2%*cos(v), ", 3);
titlin ("1.2^v%*sin(u)*cos(u)]",4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-3.,3.,-3.,1.,-3.,3.,-3.,1.,-2.,2.,-2.,1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("off", "zscale");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = p/30.;
tr3shf (-1., 0., 0.);
tr3rot (0., 0.,30.);
surfcp (zfun, 0., p, step, -p/4, 5*p/2, step);
disfin ();
}
float zfun(float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = pow (1.2, v) * (sin(u) * sin(u) * sin(v));
else if (iopt == 2)
w = pow (1.2, v) * (sin(u) * sin(u) * cos(v));
else
w = pow (1.2, v) * (sin(u) * cos(u));
return (float) w;
}
Function 5
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.14159, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 3);
titlin ("[3 * cos(u), 3 * sin(u), v]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-4.,4.,-4.,1.,-4.,4.,-4.,1.,-4.,4.,-4.,1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("off", "zscale");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = p / 20.;
surfcp (zfun, -p, p, step, -p, p, step);
disfin ();
}
float zfun(float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = 3 * cos (u);
else if (iopt == 2)
w = 3 * sin (u);
else
w = v;
return (float) w;
}
Function 6
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.14159, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 3);
titlin ("[sin(u) * sin(v), cos(u) * sin(v), cos(u) * cos(v)]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-1., 1., -1., 1., -1., 1., -1., 1., -1., 1., -1., 1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("off", "zscale");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = p/30.;
tr3rot (0., 0., 10.);
surfcp (zfun, -p, p, step, -p, p, step);
disfin ();
}
float zfun (float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = sin (u) * sin (v);
else if (iopt == 3)
w = cos (u) * sin (v);
else
w = cos (u) * cos (v);
return (float) w;
}
Function 7
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.14159, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 2);
titlin ("[sin(u) * sin(v) + 0.05 * cos(20 * v),", 3);
titlin ("cos(u) * sin(v) + 0.05 * cos(20 * u), cos(v)]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-1., 1., -1., 1., -1., 1., -1., 1., -1., 1., -1., 1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = p/60.;
tr3rot (0., 0., 10.);
surfcp (zfun, -p, p, step, -p, p, step);
disfin ();
}
float zfun (float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = sin (u) * sin (v) + 0.05 * cos (20 * v);
else if (iopt == 2)
w = cos (u) * sin (v) + 0.05 * cos (20 * u);
else
w = cos (v);
return (float) w;
}
Function 8
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
mixalf ();
newmix ();
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 3);
titlin ("[u, v, cos (sqrt (u^2% + v^2%))]", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-10.,10.,-10.,5.,-10.,10.,-10.,5.,-10.,10.,-10.,5.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("smooth", "surface");
surfcp (zfun, -10., 10., 0.5, -10., 10., 0.5);
disfin ();
}
float zfun(float u, float v, int iopt)
{ double w, r;
r = sqrt (u * u + v * v);
if (iopt == 1)
w = u;
else if (iopt == 2)
w = v;
else
w = (cos (r));
return (float) w;
}
Function 9
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float p = 3.1415926, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
intax ();
linesp (2.0);
titlin("Surface Plot of the Parametric Function", 3);
titlin("[v * cos (u), v * sin (u), v]", 4);
light ("on");
vkytit(-300);
nograf ();
graf3d (-1.,1.,-1.,1.,-1.,1.,-1.,1.,-1.,1.,-1.,1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
shdmod ("smooth", "surface");
step = p / 30.;
surfcp (zfun, 0, 2 * p, step, -1. , 1., 0.1);
disfin ();
}
float zfun(float u, float v, int iopt)
{ double w;
if (iopt == 1)
w = v * cos (u);
else if (iopt == 2)
w = v * sin (u);
else
w = v;
return (float) w;
}
Function 10
#include <stdio.h>
#include <math.h>
#include "dislin.h"
float zfun(float u, float v, int iopt);
main()
{ float pi = 3.1415926, step;
winsiz (600, 600);
page (3000, 3000);
metafl ("png");
imgfmt ("rgb");
scrmod ("revers");
disini ();
pagera ();
hwfont ();
axspos (150,2950);
axslen (2700,2700);
linesp (2.0);
titlin ("Surface Plot of the Parametric Function", 2);
titlin ("[r * sin (u) * cos (v), r * sin (u) * sin (v),", 3);
titlin ("r * cos (u)], r = cos ( 2 * u)", 4);
light ("on");
vkytit (-300);
nograf ();
graf3d (-1., 1., -1., 1., -1., 1., -1., 1., -1., 1., -1., 1.);
height (60);
title ();
clip3d ("none");
surmsh ("on");
surclr (254, 100);
survis ("both");
matop3 (1.0,0.0,0.0,"diffuse");
setfce ("bottom");
matop3 (0.0,1.0,0.0,"diffuse");
shdmod ("smooth", "surface");
step = pi / 30.;
surfcp (zfun, 0., pi, step, 0., 2 * pi, step);
disfin ();
}
float zfun (float u, float v, int iopt)
{ double w, r;
r = cos (2 * u);
if (iopt == 1)
w = r * sin (u) * cos (v);
else if (iopt == 2)
w = r * sin (u) * sin (v);
else
w = r * cos (u);
return (float) w;
}