Circle.js is a collection of functions to work with circles. The aim is to have a fast and correct library, which makes it easy to calculate the intersection of circles, the area of a circle and so on.
Every circle is defined by a cartesian point (x, y)
and the radius r
.
Circles.js is analogous to Rectangles.js and Angles.js.
const circle = require('circle.js');
const A = {x: 20, y: 20, r: 10};
const B = {x: 80, y: 80, r: 30};
if (circle.intersect(A, B)) {
console.log(circle.intersection(A, B)); // Intersection points
console.log(circle.intersectionArea(A, B)); // Intersection area
} else {
console.log("no intersection");
}
Determines if two circles intersect
Calculates the intersection points of two circles
Calculates the intersection area of two circles
Calculates the area of a circle
Calculates the height of a circle. Obviously, this is the same as the width.
Calculates the width of a circle. Obviously, this is the same as the height.
Calculates the perimeter of a circle
Calculates the center point of a circle. Simply it's coordinates.
Resizes the circle by a given value on the center
Caclulates a circle {x, y, r} with given three {x, y} points
Installing Circle.js is as easy as cloning this repo or use one of the following command:
npm install circle.js
<script src="circle.min.js"></script>
<script>
console.log(Circle.center(A));
</script>
As every library I publish, Circle.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
After cloning the Git repository run:
npm install
npm run build
Testing the source against the shipped test suite is as easy as
npm run test
Copyright (c) 2024, Robert Eisele Licensed under the MIT license.