mitsuba-af602c6fd98a/src/sensors/telecentric.cpp
/**
	 * \brief Compute the percentage of overlap between an arbitrary disk and a
	 * rectangle that is centered at the origin
	 *
	 * \remark To restrict the possible number of cases to a sane amount, the
	 * implementation here assumes that <tt>size.{x,y}/2 < radius</tt>.
	 *
	 * \param center
	 *   Center of the disk
	 * \param radius
	 *    Radius of the disk
	 * \param size
	 *    Total width and height of the rectangular region
	 * \author Wenzel Jakob
	 */
\brief Compute the percentage of overlap between an arbitrary disk and a
rectangle that is centered at the origin

\remark To restrict the possible number of cases to a sane amount, the
implementation here assumes that size.{x,y}/2 < radius.

\param center
Center of the disk
\param radius
Radius of the disk
\param size
Total width and height of the rectangular region
\author Wenzel Jakob
\ brief Compute the percentage of overlap between an arbitrary disk and a rectangle that is centered at the origin \ remark To restrict the possible number of cases to a sane amount the implementation here assumes that size . { x y } / 2 < radius . \ param center Center of the disk \ param radius Radius of the disk \ param size Total width and height of the rectangular region \ author Wenzel Jakob
Float convolve(const Point2 &center, Float radius, const Vector2 &size) const {
		Float invRadius = 1.0f / radius,
		      x = (0.5f * size.x - std::abs(center.x)) * invRadius,
		      y = (0.5f * size.y - std::abs(center.y)) * invRadius;
		if (x < -1 || y < -1 || (x < 0 && y < 0 && x*x+y*y > 1)) {
			return 0.0f; 
		} else if (x >= 1 && y >= 1) {
			return 1.0f; 
		} else if (x >= 0 && x <= 1 && y >= 0 && y <= 1 && x*x+y*y > 1) {
			return INV_PI * (x * std::sqrt(1-x*x) + y * std::sqrt(1-y*y) + std::asin(x) + std::asin(y));
		} else if (x*x + y*y <= 1) {
			Float yt = -std::sqrt(1-x*x), xt = -std::sqrt(1-y*y),
			      ct = x*xt + y*yt;
			return INV_TWOPI * ((x-xt) * (y-yt) + math::safe_acos(ct) - math::safe_sqrt(1-ct*ct));
		} else {
			Float h = std::min(x, y);
			return INV_PI * (std::acos(-h) + h*std::sqrt(1-h*h));
		}
	}
Float convolve ( const Point2 & center , Float radius , const Vector2 & size ) const { Float invRadius = 1.0f / radius , x = ( 0.5f * size . x - std :: abs ( center . x ) ) * invRadius , y = ( 0.5f * size . y - std :: abs ( center . y ) ) * invRadius ; if ( x < -1 || y < -1 || ( x < 0 && y < 0 && x * x + y * y > 1 ) ) { return 0.0f ; } else if ( x >= 1 && y >= 1 ) { return 1.0f ; } else if ( x >= 0 && x <= 1 && y >= 0 && y <= 1 && x * x + y * y > 1 ) { return INV_PI * ( x * std :: sqrt ( 1 - x * x ) + y * std :: sqrt ( 1 - y * y ) + std :: asin ( x ) + std :: asin ( y ) ) ; } else if ( x * x + y * y <= 1 ) { Float yt = - std :: sqrt ( 1 - x * x ) , xt = - std :: sqrt ( 1 - y * y ) , ct = x * xt + y * yt ; return INV_TWOPI * ( ( x - xt ) * ( y - yt ) + math :: safe_acos ( ct ) - math :: safe_sqrt ( 1 - ct * ct ) ) ; } else { Float h = std :: min ( x , y ) ; return INV_PI * ( std :: acos ( - h ) + h * std :: sqrt ( 1 - h * h ) ) ; } }
\brief Compute the percentage of overlap between an arbitrary disk and a
 rectangle that is centered at the origin
\ brief Compute the percentage of overlap between an arbitrary disk and a rectangle that is centered at the origin
/* Coordinates of the lower right rectangle corner in the disc frame */ /* No coverage at all */ /* Full coverage */ /* There are four intersections. Area = full circle - 2 circular segments */ /* There are two intersections (case 1): area = 1 circular segment + 1 triangle. */ /* There are two intersections (case 2): area = 1 circular segment only */