User Tools

Site Tools


hyperfun:hf_program

HyperFun: Program

The program in HyperFun consists of one or few objects defined one after another. The previous objects can be used in functional expressions of the following ones.

Example of a program without attributes:

-- The program contains the definitions of three objects
-- Definition of object "Parallelepiped"
Parallelepiped(x[3], a[6])
{
Parallelepiped = (x[1] - a[1]) & (-(x[1] - a[1]) + a[4]) &
(x[2] - a[2]) & (-(x[2] - a[2]) + a[5] &
(x[3] - a[3]) & (-(x[3] - a[3]) + a[6]));
}
-- Definition of object "Sphere"
Sphere(x[3], a[1])
{
Sphere = a[1]^2 - x[1]^2 - x[2]^2 - x[3]^2;
}
-- Definition of object "CSGobj" using previously defined objects
CSGobj(x[3], a[1])
{
array param[6], rad[1];
param = [-9.0, -8., -9, 18.0, 16., 18];
rad[1] = 10.;
block = Parallelepiped(x, param);
CSGobj = block \ Sphere(x,rad);
}

Example of a program consisting of two objects with attributes:

-- The program contains the definitions of two objects
-- Definition of object Color Sphere
ColorSphere(x[3], a[4], s[3]) {
-- в__sв_T is input/output parameter
array center[3], rgb[3];
center[1] = a[1]; center[2] = a[2]; center[3] = a[3];
radius = a[4];
rgb[1] = s[1]; rgb[2] = s[2]; rgb[3] = s[3];
s   = [0, 0, 0];
sphere = hfSphere(x, center, radius);
 
-- association the sphereв_Ts interior and surface with the color
        if (sphere >= 0) then
        s[1] = rgb[1]; s[2] = rgb[2]; s[3] = rgb[3];
        endif;
 
ColorSphere = sphere;
}
-- Definition of object "my_model" using previously defined ColorSphere
my_model(x[3], a[1], s[4]) {
array BlockCenter[3];
array rgb1[3], rgb2[3];
array SpherePar[4];
 
rgb1= [1,0,0];
rgb2= [0,0,1];
 
s = [0.0,1.0,0.0, 0.0];
 
SpherePar[1] = [0,0,0,1];
 
SphereRadius = a[1];
 
BlockCenter = [-7,-7,-7];
model = hfBlock(x, Blockcenter, 14, 7, 14);
 
if(model>-0.1) then
       
s[1] = rgb1[1]; s[2] = rgb1[2]; s[3] = rgb1[3];
tmp = ColorSphere(x, SpherePar, s);
       
 SpherePar[1]= 7;
s[1] = rgb2[1]; s[2] = rgb2[2]; s[3] = rgb2[3];
 tmp = ColorSphere(x, SpherePar, s);
 
endif; 
 
my_model = model;
 
}
hyperfun/hf_program.txt · Last modified: 2020/12/31 10:49 (external edit)