MCPcopy Create free account
hub / github.com/FreeFem/FreeFem-sources / trackHyperbolaCore

Function trackHyperbolaCore

plugin/seq/plotPDF.cpp:2381–2451  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2379 Cx.push_back( Cx_local );
2380 Cy.push_back( Cy_local );
2381 }
2382
2383 return;
2384}
2385
2386void trackHyperbolaCore( std::vector< std::vector<double> > &Cx, std::vector< std::vector<double> > &Cy,
2387 const double sign, const double a, const double b, std::vector<double> &x,
2388 const double *const Vx, const double *const Vy )
2389{
2390 const int INTERVALS = PLOTPDFVAR::DEFAULT_P2_INERVALS;
2391
2392 // y = sign * sqrt( a * x^2 + b )
2393
2394 std::sort( x.begin(), x.end() );
2395
2396 std::vector<double> Y;
2397 for(size_t i = 0; i < x.size(); i++)
2398 Y.push_back( sign * sqrt( a*x[i]*x[i] + b ) );
2399
2400 // algorithm in "Mathematical Illustrations" by Bill Casselman,
2401 // Chapter 7, (2005) Cambridge University Press.
2402 // https://www.cambridge.org/jp/academic/subjects/mathematics/geometry-and-topology/mathematical-illustrations-manual-geometry-and-postscript?format=PB&isbn=9780521547888
2403 // See also http://www.math.ubc.ca/~cass/graphics/text/www/
2404
2405 for(size_t i = 0; i+1 < x.size(); i++){
2406
2407 std::vector<double> Cx_local, Cy_local;
2408
2409 const double &X0 = x[i];
2410 const double &X1 = x[i+1];
2411 const double h = (X1 - X0) / INTERVALS;
2412
2413 const double EPS = 1e-10;
2414 if( h < EPS )
2415 continue;
2416
2417 // examine the arc X[i]--X[i+1] is inside triangle or not
2418 const double mX0 = X0 + h/100;
2419 const double mY0 = sign * sqrt( a*mX0*mX0 + b );
2420
2421 const double mX1 = X1 - h/100;
2422 const double mY1 = sign * sqrt( a*mX1*mX1 + b );
2423 if( !(isInsideTriangle( mX0, mY0, Vx, Vy ) && isInsideTriangle( mX1, mY1, Vx, Vy )) )
2424 continue;
2425
2426 Cx_local.push_back( X0 );
2427 Cy_local.push_back( Y[i] );
2428
2429 for(int k = 0; k < INTERVALS; k++){
2430
2431 const double P0x = X0 + k*h;
2432 const double P3x = X0 + (k+1)*h;
2433 const double P1x = P0x + h/3;
2434 const double P2x = P3x - h/3;
2435
2436 const double P0y = sign * sqrt( a*P0x*P0x + b );
2437 const double P3y = sign * sqrt( a*P3x*P3x + b );
2438 // y = f(x) = sqrt(a*x*x + b)

Callers 1

trackHyperbolaFunction · 0.85

Calls 6

isInsideTriangleFunction · 0.85
sqrtFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected