001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.commons.math3.geometry.spherical.twod; 019 020import java.io.Serializable; 021 022import org.apache.commons.math3.geometry.Space; 023import org.apache.commons.math3.geometry.spherical.oned.Sphere1D; 024 025/** 026 * This class implements a two-dimensional sphere (i.e. the regular sphere). 027 * <p> 028 * We use here the topologists definition of the 2-sphere (see 029 * <a href="http://mathworld.wolfram.com/Sphere.html">Sphere</a> on 030 * MathWorld), i.e. the 2-sphere is the two-dimensional surface 031 * defined in 3D as x<sup>2</sup>+y<sup>2</sup>+z<sup>2</sup>=1. 032 * </p> 033 * @since 3.3 034 */ 035public class Sphere2D implements Serializable, Space { 036 037 /** Serializable version identifier. */ 038 private static final long serialVersionUID = 20131218L; 039 040 /** Private constructor for the singleton. 041 */ 042 private Sphere2D() { 043 } 044 045 /** Get the unique instance. 046 * @return the unique instance 047 */ 048 public static Sphere2D getInstance() { 049 return LazyHolder.INSTANCE; 050 } 051 052 /** {@inheritDoc} */ 053 public int getDimension() { 054 return 2; 055 } 056 057 /** {@inheritDoc} */ 058 public Sphere1D getSubSpace() { 059 return Sphere1D.getInstance(); 060 } 061 062 // CHECKSTYLE: stop HideUtilityClassConstructor 063 /** Holder for the instance. 064 * <p>We use here the Initialization On Demand Holder Idiom.</p> 065 */ 066 private static class LazyHolder { 067 /** Cached field instance. */ 068 private static final Sphere2D INSTANCE = new Sphere2D(); 069 } 070 // CHECKSTYLE: resume HideUtilityClassConstructor 071 072 /** Handle deserialization of the singleton. 073 * @return the singleton instance 074 */ 075 private Object readResolve() { 076 // return the singleton instance 077 return LazyHolder.INSTANCE; 078 } 079 080}