home | career | drupal | java | mac | mysql | perl | scala | uml | unix

# Java example source code file (Circle.java)

This example Java source code file (Circle.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

## Java - Java tags/keywords

arc, arcsset, circle, circletransform, embedding, hyperplane, rotation, s1point, s2point, sphere1d, sphericalpolygonsset, subcircle, subhyperplane, vector3d

## The Circle.java Java example source code

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*/
package org.apache.commons.math3.geometry.spherical.twod;

import org.apache.commons.math3.geometry.Point;
import org.apache.commons.math3.geometry.euclidean.threed.Rotation;
import org.apache.commons.math3.geometry.euclidean.threed.Vector3D;
import org.apache.commons.math3.geometry.partitioning.Embedding;
import org.apache.commons.math3.geometry.partitioning.Hyperplane;
import org.apache.commons.math3.geometry.partitioning.SubHyperplane;
import org.apache.commons.math3.geometry.partitioning.Transform;
import org.apache.commons.math3.geometry.spherical.oned.Arc;
import org.apache.commons.math3.geometry.spherical.oned.ArcsSet;
import org.apache.commons.math3.geometry.spherical.oned.S1Point;
import org.apache.commons.math3.geometry.spherical.oned.Sphere1D;
import org.apache.commons.math3.util.FastMath;

/** This class represents an oriented great circle on the 2-sphere.

* <p>An oriented circle can be defined by a center point. The circle
* is the the set of points that are in the normal plan the center.</p>

* <p>Since it is oriented the two spherical caps at its two sides are
* unambiguously identified as a left cap and a right cap. This can be
* used to identify the interior and the exterior in a simple way by
* local properties only when part of a line is used to define part of
* a spherical polygon boundary.</p>

* @since 3.3
*/
public class Circle implements Hyperplane<Sphere2D>, Embedding {

/** Pole or circle center. */
private Vector3D pole;

/** First axis in the equator plane, origin of the phase angles. */
private Vector3D x;

/** Second axis in the equator plane, in quadrature with respect to x. */
private Vector3D y;

/** Tolerance below which close sub-arcs are merged together. */
private final double tolerance;

/** Build a great circle from its pole.
* <p>The circle is oriented in the trigonometric direction around pole.

* @param pole circle pole * @param tolerance tolerance below which close sub-arcs are merged together */ public Circle(final Vector3D pole, final double tolerance) { reset(pole); this.tolerance = tolerance; } /** Build a great circle from two non-aligned points. * <p>The circle is oriented from first to second point using the path smaller than $$\pi$$.

* @param first first point contained in the great circle * @param second second point contained in the great circle * @param tolerance tolerance below which close sub-arcs are merged together */ public Circle(final S2Point first, final S2Point second, final double tolerance) { reset(first.getVector().crossProduct(second.getVector())); this.tolerance = tolerance; } /** Build a circle from its internal components. * <p>The circle is oriented in the trigonometric direction around center.

* @param pole circle pole * @param x first axis in the equator plane * @param y second axis in the equator plane * @param tolerance tolerance below which close sub-arcs are merged together */ private Circle(final Vector3D pole, final Vector3D x, final Vector3D y, final double tolerance) { this.pole = pole; this.x = x; this.y = y; this.tolerance = tolerance; } /** Copy constructor. * <p>The created instance is completely independent from the * original instance, it is a deep copy.</p> * @param circle circle to copy */ public Circle(final Circle circle) { this(circle.pole, circle.x, circle.y, circle.tolerance); } /** {@inheritDoc} */ public Circle copySelf() { return new Circle(this); } /** Reset the instance as if built from a pole. * <p>The circle is oriented in the trigonometric direction around pole.