package com.thealgorithms.physics; /** * Implements the Thin Lens Formula used in ray optics: * *
* 1/f = 1/v + 1/u ** * where: *
* m = v / u
*
*
* @param imageDistance image distance (v)
* @param objectDistance object distance (u)
* @return magnification
* @throws IllegalArgumentException if object distance is zero
*/
public static double magnification(double imageDistance, double objectDistance) {
if (objectDistance == 0) {
throw new IllegalArgumentException("Object distance must be non-zero.");
}
return imageDistance / objectDistance;
}
/**
* Determines whether the image formed is real or virtual.
*
* @param imageDistance image distance (v)
* @return {@code true} if image is real, {@code false} if virtual
*/
public static boolean isRealImage(double imageDistance) {
return imageDistance > 0;
}
}