Giter VIP home page Giter VIP logo

circle-circle-intersection's Introduction

Circle-to-Circle Intersections in Java

Copyright 2012, Rodrigo Balerdi. Licensed under the GNU General Public License (GPL) Version 3 or later.

A year ago I needed free code to compute coplanar circle-to-circle intersections in Java and could not find any. So I wrote this and forgot to release it.

References

Usage

Construct a CircleCircleIntersection from two Circle instances c1 and c2 to solve an intersection. Note that degenerate circles (zero radius) cannot be constructed.

The type of an intersection will be one of:

COINCIDENT
CONCENTRIC_CONTAINED
ECCENTRIC_CONTAINED
INTERNALLY_TANGENT
OVERLAPPING
EXTERNALLY_TANGENT
SEPARATE

You can query the Type object for some generic properties of the type:

int getIntersectionPointCount();                    // -1 if count is infinite (coincident circles)
boolean isConcentric();
boolean isContained();
boolean isTangent();
boolean isDisjoint();

The CircleCircleIntersection object itself will contain the immutable results of the intersection.

Results valid for all intersections:

Type type;                                          // type of intersection
double distanceC1cC2c;                              // distance between circle centers

Results valid for eccentric circles:

Vector2 radicalPoint;                               // intersection between line connecting circle centers and radical line
double distanceC1cRadicalLine;                      // signed distances from circle centers to radical line
double distanceC2cRadicalLine;                      // (the direction to the other center is positive)
Vector2 versorC1cC2c;                               // direction versor from c1 center to c2 center
Vector2 versorRadicalLine;                          // direction versor of radical line
                                                    // (points to the left if looking from c1 center to c2 center)

Results valid for tangent circles:

Vector2 intersectionPoint;                          // intersection point

Results valid for overlapping circles:

Vector2 intersectionPoint1;                         // intersection points
Vector2 intersectionPoint2;                         // (point 1 is on the left if looking from c1 center to c2 center)
double distanceRadicalPointIntersectionPoints;      // distance between radical point and either intersection point

Method valid for noncoincident circles:

Vector2[] getIntersectionPoints();                  // array of 0, 1 or 2 intersection points (throws if coincident circles)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.