Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /**
     * Checks if the point lies between two circles.
     * @param x The x coordinate of the point.
     * @param y The y coordinate of the point.
     * @param centerX The x coordinate of the center.
     * @param centerY The y coordinate of the center.
     * @param radiusInnerCircle Radius of the smaller circle.
     * @param radiusOuterCircle Radius of the larger circle.
     * @return true if the point is in between the two circles, false otherwise.
     */
    public static boolean pointLiesBetweenCircles(float x, float y, float centerX, float centerY,
            float radiusInnerCircle, float radiusOuterCircle) {

        float deltaX = Math.abs(centerX - x);

        if (deltaX > radiusOuterCircle && deltaX < radiusInnerCircle) {
            return false;
        }

        float deltaY = Math.abs(centerY - y);

        if (deltaY > radiusOuterCircle && deltaY < radiusInnerCircle) {
            return false;
        }

        float deltaXSquared = deltaX * deltaX;
        float deltaYSquared = deltaY * deltaY;

        return (deltaXSquared + deltaYSquared <= radiusOuterCircle * radiusOuterCircle)
                && (deltaXSquared + deltaYSquared >= radiusInnerCircle * radiusInnerCircle);
    }
}