/** * <p>Calculate the area of a circle with radius {@code r}.</p> * * @param r The radius * * @return The circle area */ public static double getCircleArea( final double r) { Preconditions.checkPreconditionD( r, r > 0.0, c -> "Radius must be positive"); return Math.PI * (r * r); }
/** * <p>Calculate the area of one of the triangles that make up an approximation * of a circle with radius {@code r} constructed with {@code s} line * segments.</p> * * @param r The radius * @param s The number of segments in the approximation * * @return The approximation area */ public static double getUVSphereApproximationTriangleArea( final double r, final int s) { Preconditions.checkPreconditionI( s, s > 0, c -> "Segment count must be positive"); Preconditions.checkPreconditionD( r, r > 0.0, c -> "Radius must be positive"); final double a = getUVSphereTriangleInteriorAngle(s); final double rs = r * r; return 0.5 * rs * Math.sin(a); }
/** * A {@code double} specialized version of {@link #checkPrecondition(Object, * ContractConditionType)}. * * @param value The value * @param condition The predicate * * @return value * * @throws PreconditionViolationException If the predicate is false */ public static double checkPreconditionD( final double value, final ContractDoubleConditionType condition) throws PreconditionViolationException { return checkPreconditionD( value, condition.predicate(), condition.describer()); }
/** * A {@code double} specialized version of {@link #checkPrecondition(Object, * ContractConditionType)}. * * @param value The value * @param condition The predicate * * @return value * * @throws PreconditionViolationException If the predicate is false */ public static double checkPreconditionD( final double value, final ContractDoubleConditionType condition) throws PreconditionViolationException { return checkPreconditionD( value, condition.predicate(), condition.describer()); }
/** * <p>Calculate the area of an approximation of a circle with radius {@code r} * constructed with {@code s} line segments.</p> * * @param r The radius * @param s The number of segments in the approximation * * @return The approximation area */ public static double getUVSphereApproximationArea( final double r, final int s) { Preconditions.checkPreconditionI( s, s > 0, c -> "Segment count must be positive"); Preconditions.checkPreconditionD( r, r > 0.0, c -> "Radius must be positive"); final double ds = (double) s; final double a = getUVSphereApproximationTriangleArea(r, s); return ds * a; }
/** * <p>Calculate the scale factor required to completely contain a circle of * radius {@code r} inside an approximation with radius {@code r} constructed * with {@code s} line segments.</p> * * @param r The radius * @param s The number of segments in the approximation * * @return The approximation area */ public static double getUVSphereApproximationScaleFactor( final double r, final int s) { Preconditions.checkPreconditionI( s, s > 0, c -> "Segment count must be positive"); Preconditions.checkPreconditionD( r, r > 0.0, c -> "Radius must be positive"); final double ac = getCircleArea(r); final double aa = getUVSphereApproximationArea(r, s); return ac / aa; }