int mapdist(int x1, int y1, int x2, int y2) { int dx, dy; dx = deltax(x1, x2); dy = deltay(y1, y2); if (dx > dy) return (dx - dy) / 2 + dy; return dy; }
void NewtonSystem::findSolution(MyFunction1 f, MyFunction2 g, double x0, double y0) { double k = 2; double xk = x0; double yk = y0; double xk1 = xk + deltax(f, g, xk, yk) / delta(f, g, xk, yk); double yk1 = yk + deltay(f, g, xk, yk) / delta(f, g, xk, yk); cout << "0 " << xk << " " << yk << " " << f.value(xk, yk) << " " << g.value(xk, yk) << endl; cout << "1 " << xk1 << " " << yk1 << " " << f.value(xk1, yk1) << " " << g.value(xk1, yk1) << endl; while (fabs(xk1 - xk) > eps && fabs(yk1 - yk) > eps) { double xtmp = xk1; double ytmp = yk1; xk1 = xtmp + deltax(f, g, xtmp, ytmp) / delta(f, g, xtmp, ytmp); yk1 = ytmp + deltay(f, g, xtmp, ytmp) / delta(f, g, xtmp, ytmp); xk = xtmp; yk = ytmp; cout << k << " " << xk1 << " " << yk1 << " " << f.value(xk1, yk1) << " " << g.value(xk1, yk1) << endl; k++; } }
int main(int argc, char** argv) { int l=5; TinyVector<double,3> pos(0.1,0.3,-0.45), deltax(0.0001,0.0,0.0), deltay(0.0,0.0001,0.0), deltaz(0.0,0.0,0.0001), tpos, g; if(argc>1) l = atoi(argv[1]); if(argc>4) { pos[0] = atof(argv[2]); pos[1] = atof(argv[3]); pos[2] = atof(argv[4]); } SphericalTensor<double,TinyVector<double,3> > Y1(l,true), Y2(l,true), Yp(l,true), Ym(l,true); Y1.evaluate(pos); std::cout.setf(std::ios::scientific, std::ios::floatfield); for(int lm=0; lm<Y1.size(); lm++) { std::cout << lm << std::endl; std::cout << std::setw(20) << std::setprecision(12) << Y1.Ylm[lm] << std::setprecision(12) << Y1.gradYlm[lm] << std::endl; //std::cout << std::setw(20) << std::setprecision(12) << Y2.Ylm[lm] // << std::setprecision(12) << Y2.gradYlm[lm] << std::endl; } // for(int lm=0; lm<Y1.size(); lm++) { // tpos = pos+deltax; Yp.evaluate(tpos); // tpos = pos-deltax; Ym.evaluate(tpos); // g[0] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002; // tpos = pos+deltay; Yp.evaluate(tpos); // tpos = pos-deltay; Ym.evaluate(tpos); // g[1] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002; // tpos = pos+deltaz; Yp.evaluate(tpos); // tpos = pos-deltaz; Ym.evaluate(tpos); // g[2] = (Yp.Ylm[lm]-Ym.Ylm[lm])/0.0002; // std::cout << lm << std::endl; // std::cout << std::setw(20) << std::setprecision(12) << Y1.Ylm[lm] // << std::setprecision(12) << Y1.gradYlm[lm] - g << std::endl; // } }
void HGPrintElt(ELT *element, int /* baseline */) { register POINT *p1; register POINT *p2; register int length; register int graylevel; if (!DBNullelt(element) && !Nullpoint((p1 = element->ptlist))) { /* p1 always has first point */ if (TEXT(element->type)) { HGSetFont(element->brushf, element->size); switch (element->size) { case 1: p1->y += adj1; break; case 2: p1->y += adj2; break; case 3: p1->y += adj3; break; case 4: p1->y += adj4; break; default: break; } HGPutText(element->type, *p1, element->textpt); } else { if (element->brushf) /* if there is a brush, the */ HGSetBrush(element->brushf); /* graphics need it set */ switch (element->type) { case ARC: p2 = PTNextPoint(p1); tmove(p2); doarc(*p1, *p2, element->size); cr(); break; case CURVE: length = 0; /* keep track of line length */ drawwig(p1, CURVE); cr(); break; case BSPLINE: length = 0; /* keep track of line length */ drawwig(p1, BSPLINE); cr(); break; case VECTOR: length = 0; /* keep track of line length so */ tmove(p1); /* single lines don't get long */ while (!Nullpoint((p1 = PTNextPoint(p1)))) { HGtline((int) (p1->x * troffscale), (int) (p1->y * troffscale)); if (length++ > LINELENGTH) { length = 0; printf("\\\n"); } } /* end while */ cr(); break; case POLYGON: { /* brushf = style of outline; size = color of fill: * on first pass (polyfill=FILL), do the interior using 'P' * unless size=0 * on second pass (polyfill=OUTLINE), do the outline using a series * of vectors. It might make more sense to use \D'p ...', * but there is no uniform way to specify a 'fill character' * that prints as 'no fill' on all output devices (and * stipple fonts). * If polyfill=BOTH, just use the \D'p ...' command. */ double firstx = p1->x; double firsty = p1->y; length = 0; /* keep track of line length so */ /* single lines don't get long */ if (polyfill == FILL || polyfill == BOTH) { /* do the interior */ char command = (polyfill == BOTH && element->brushf) ? 'p' : 'P'; /* include outline, if there is one and */ /* the -p flag was set */ /* switch based on what gremlin gives */ switch (element->size) { case 1: graylevel = 1; break; case 3: graylevel = 2; break; case 12: graylevel = 3; break; case 14: graylevel = 4; break; case 16: graylevel = 5; break; case 19: graylevel = 6; break; case 21: graylevel = 7; break; case 23: graylevel = 8; break; default: /* who's giving something else? */ graylevel = NSTIPPLES; break; } /* int graylevel = element->size; */ if (graylevel < 0) break; if (graylevel > NSTIPPLES) graylevel = NSTIPPLES; printf("\\D'Fg %.3f'", double(1000 - stipple_index[graylevel]) / 1000.0); cr(); tmove(p1); printf("\\D'%c", command); while (!Nullpoint((PTNextPoint(p1)))) { p1 = PTNextPoint(p1); deltax((double) p1->x); deltay((double) p1->y); if (length++ > LINELENGTH) { length = 0; printf("\\\n"); } } /* end while */ /* close polygon if not done so by user */ if ((firstx != p1->x) || (firsty != p1->y)) { deltax((double) firstx); deltay((double) firsty); } putchar('\''); cr(); break; } /* else polyfill == OUTLINE; only draw the outline */ if (!(element->brushf)) break; length = 0; /* keep track of line length */ tmove(p1); while (!Nullpoint((PTNextPoint(p1)))) { p1 = PTNextPoint(p1); HGtline((int) (p1->x * troffscale), (int) (p1->y * troffscale)); if (length++ > LINELENGTH) { length = 0; printf("\\\n"); } } /* end while */ /* close polygon if not done so by user */ if ((firstx != p1->x) || (firsty != p1->y)) { HGtline((int) (firstx * troffscale), (int) (firsty * troffscale)); } cr(); break; } /* end case POLYGON */ } /* end switch */ } /* end else Text */ } /* end if */ } /* end PrintElt */
CVector3 cRenderWorker::CalculateNormals(const sShaderInputData &input) { CVector3 normal(0.0, 0.0, 0.0); // calculating normal vector based on distance estimation (gradient of distance function) if (!params->slowShading) { double delta = input.delta * params->smoothness; if (params->interiorMode) delta = input.distThresh * 0.2 * params->smoothness; double sx1, sx2, sy1, sy2, sz1, sz2; sDistanceOut distanceOut; CVector3 deltax(delta, 0.0, 0.0); sDistanceIn distanceIn1(input.point + deltax, input.distThresh, true); sx1 = CalculateDistance(*params, *fractal, distanceIn1, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; sDistanceIn distanceIn2(input.point - deltax, input.distThresh, true); sx2 = CalculateDistance(*params, *fractal, distanceIn2, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; CVector3 deltay(0.0, delta, 0.0); sDistanceIn distanceIn3(input.point + deltay, input.distThresh, true); sy1 = CalculateDistance(*params, *fractal, distanceIn3, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; sDistanceIn distanceIn4(input.point - deltay, input.distThresh, true); sy2 = CalculateDistance(*params, *fractal, distanceIn4, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; CVector3 deltaz(0.0, 0.0, delta); sDistanceIn distanceIn5(input.point + deltaz, input.distThresh, true); sz1 = CalculateDistance(*params, *fractal, distanceIn5, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; sDistanceIn distanceIn6(input.point - deltaz, input.distThresh, true); sz2 = CalculateDistance(*params, *fractal, distanceIn6, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; normal.x = sx1 - sx2; normal.y = sy1 - sy2; normal.z = sz1 - sz2; } // calculating normal vector based on average value of binary central difference else { CVector3 point2; CVector3 point3; double delta = input.delta * params->smoothness * 0.5; if (params->interiorMode) delta = input.distThresh * 0.2 * params->smoothness; sDistanceOut distanceOut; for (point2.x = -1.0; point2.x <= 1.0; point2.x += 0.2) //+0.2 { for (point2.y = -1.0; point2.y <= 1.0; point2.y += 0.2) { for (point2.z = -1.0; point2.z <= 1.0; point2.z += 0.2) { point3 = input.point + point2 * delta; sDistanceIn distanceIn(point3, input.distThresh, true); double dist = CalculateDistance(*params, *fractal, distanceIn, &distanceOut, data); data->statistics.totalNumberOfIterations += distanceOut.totalIters; normal += (point2 * dist); } } } } if ((normal.x == 0 && normal.y == 0 && normal.z == 0)) { normal = CVector3(1.0, 0.0, 0.0); } else { normal.Normalize(); } if (normal.IsNotANumber()) { normal = CVector3(1.0, 0.0, 0.0); } if (input.invertMode) normal *= (-1.0); // qDebug() << input.point.Debug() << normal.Debug(); return normal; }
// will be done later sRGBAfloat cRenderWorker::FakeLights(const sShaderInputData &input, sRGBAfloat *fakeSpec) { sRGBAfloat fakeLights; double delta = input.distThresh * params->smoothness; sFractalIn fractIn(input.point, params->minN, params->N, params->common, -1); sFractalOut fractOut; Compute<fractal::calcModeOrbitTrap>(*fractal, fractIn, &fractOut); double rr = fractOut.orbitTrapR; double fakeLight = params->fakeLightsIntensity / rr; double r = 1.0 / (rr + 1e-30); CVector3 deltax(delta, 0.0, 0.0); CVector3 deltay(0.0, delta, 0.0); CVector3 deltaz(0.0, 0.0, delta); fractIn.point = input.point + deltax; Compute<fractal::calcModeOrbitTrap>(*fractal, fractIn, &fractOut); double rx = 1.0 / (fractOut.orbitTrapR + 1e-30); fractIn.point = input.point + deltay; Compute<fractal::calcModeOrbitTrap>(*fractal, fractIn, &fractOut); double ry = 1.0 / (fractOut.orbitTrapR + 1e-30); fractIn.point = input.point + deltaz; Compute<fractal::calcModeOrbitTrap>(*fractal, fractIn, &fractOut); double rz = 1.0 / (fractOut.orbitTrapR + 1e-30); CVector3 fakeLightNormal; fakeLightNormal.x = r - rx; fakeLightNormal.y = r - ry; fakeLightNormal.z = r - rz; if (fakeLightNormal.x == 0 && fakeLightNormal.y == 0 && fakeLightNormal.z == 0) { fakeLightNormal.x = 0.0; } else { fakeLightNormal.Normalize(); } double fakeLight2 = fakeLight * input.normal.Dot(fakeLightNormal); if (fakeLight2 < 0) fakeLight2 = 0; fakeLights.R = fakeLight2; fakeLights.G = fakeLight2; fakeLights.B = fakeLight2; CVector3 half = fakeLightNormal - input.viewVector; half.Normalize(); double fakeSpecular = input.normal.Dot(half); if (fakeSpecular < 0.0) fakeSpecular = 0.0; double diffuse = 10.0 * (1.1 - input.material->diffussionTextureIntensity * (input.texDiffuse.R + input.texDiffuse.G + input.texDiffuse.B) / 3.0); fakeSpecular = pow(fakeSpecular, 30.0 / input.material->specularWidth / diffuse) / diffuse; if (fakeSpecular > 15.0) fakeSpecular = 15.0; fakeSpec->R = fakeSpecular; fakeSpec->G = fakeSpecular; fakeSpec->B = fakeSpecular; *fakeSpec = sRGBAfloat(); return fakeLights; }