``````float y1, float (*f)( float, float), int n1, int n2, int nLines )
{
float * fVal = new float [n1*n2]; float hx =(x1 -x0)/n1; float hy = ( y1 - yO ) / n2;
int xStep = getmaxx () / n1;
int yStep = getmaxy () / n2;
moveto ( 0, 0 );
lineto((n1 -1 )*xStep, 0);
iineto (( n1 - 1 ) * xStep, ( n2 -1 ) * yStep );
lineto ( 0, ( n2 - 1 ) * yStep );
Iineto (0, 0 );
for (int i = 0; i < n1; i++ )``````

3. Графические примитивы

``````for (int j = 0; j < n2; j++ )
fVal [i + j*n1] = f ( xO + i*hx, yO + j*hy );
float zMin = tVal [0]; float zMax = fVal [0];
for (i = 0; i < n1 * n2; i++ ) if (fVal [i] < zMin )
zMin = fVal [i]; else
if (fVal [i] > zMax ) zMax = fVal [i];
float dz = ( zMax - zMin ) / nLines; Point p [3];
for (i = 0; i < n1 -1; i++ ) for (int j = 0; j < n2 -1; j++ )
{
int k = i+j*n1; int x = i * xStep;
int y = j * yStep;
float t;
for (float z = zMin; z <= zMax; z += dz ) {
int count = 0; // edge 0-1
if (fVal [k] !=fVa! [k+1]) {
t = (z - fVal [k])/(fVal [k+1] - fVal [k]);
if (t >= 0 && t <= 1 ) {
p [count ].x = (int)( x +1 * xStep ); p [count++].y = y;
}
}
//edge 1-3
if (fVal [k+1] !=fVal [k+n1]) {
t = (z-fVal[k+n1])/(fVal[k+1]-fVal[k+n1]);
if (t >= 0 && t <= 1 ) {
p [count ].x = (int)( x + t * xStep ); p [count++].y = (int)(y+(1-t)*yStep);
}
}
// edge 3-0
if(fVal[k]!=fVal[k+n1]) {
t = (z - fVal[k+n1])/(fVa![k] - fVal[k+n1]); if (t >= 0 && t <= 1 )``````

Компьютерная графика. Полигональные модели

``````{
p [count ].x = x;
p [count++].y = y + ( 1 -1 ) * yStep;
}
}
if ( count > 0 )
line(p[0].x, p[0].y,p[1].xf p[1].y);
if ( count > 2 ) // line through vertex
line ( p [1].x, p[1].y, p[2].x, p[2].y );
count = 0; .
//edge 1-2
if (fVal [k+1] !=fVal [k+n1+1] ) {
t = (2-fVai[k+1])/(fVal[k+n1+1]-fVal[k+1]);
if ( t >= 0 && t <= 1 ) {
p [count ].x = x + xStep; p [count++].y = y + t * yStep;
}
}
// edge 2-3
if (A/al [k+n1] !=fVal [k+n1+1] ) {
t = (2-fVal[k+n1])/(fVal[k+n1+1]-fVal[k+n1]);
if ( t >= 0 && t <= 1 ) {
p [count ].x = x +1 * xStep; p [count++].y = y + yStep;``````

⇐ Предыдущая| |Следующая ⇒