1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * https://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* 19 * This is not the original file distributed by the Apache Software Foundation 20 * It has been modified by the Hipparchus project 21 */ 22 package org.hipparchus.analysis.interpolation; 23 24 import org.hipparchus.util.FastMath; 25 import org.hipparchus.util.MathUtils; 26 import org.hipparchus.util.SinCos; 27 28 /** 29 * Utility class for the {@link MicrosphereProjectionInterpolator} algorithm. 30 * For 2D interpolation, this class constructs the microsphere as a series of 31 * evenly spaced facets (rather than generating random normals as in the 32 * base implementation). 33 * 34 */ 35 public class InterpolatingMicrosphere2D extends InterpolatingMicrosphere { 36 /** Space dimension. */ 37 private static final int DIMENSION = 2; 38 39 /** 40 * Create a sphere from vectors regularly sampled around a circle. 41 * 42 * @param size Number of surface elements of the sphere. 43 * @param maxDarkFraction Maximum fraction of the facets that can be dark. 44 * If the fraction of "non-illuminated" facets is larger, no estimation 45 * of the value will be performed, and the {@code background} value will 46 * be returned instead. 47 * @param darkThreshold Value of the illumination below which a facet is 48 * considered dark. 49 * @param background Value returned when the {@code maxDarkFraction} 50 * threshold is exceeded. 51 * @throws org.hipparchus.exception.MathIllegalArgumentException 52 * if {@code size <= 0}. 53 * @throws org.hipparchus.exception.MathIllegalArgumentException if 54 * {@code darkThreshold < 0}. 55 * @throws org.hipparchus.exception.MathIllegalArgumentException if 56 * {@code maxDarkFraction} does not belong to the interval {@code [0, 1]}. 57 */ 58 public InterpolatingMicrosphere2D(int size, 59 double maxDarkFraction, 60 double darkThreshold, 61 double background) { 62 super(DIMENSION, size, maxDarkFraction, darkThreshold, background); 63 64 // Generate the microsphere normals. 65 for (int i = 0; i < size; i++) { 66 final double angle = i * MathUtils.TWO_PI / size; 67 final SinCos scAngle = FastMath.sinCos(angle); 68 69 add(new double[] { scAngle.cos(), 70 scAngle.sin() }, 71 false); 72 } 73 } 74 75 /** 76 * Copy constructor. 77 * 78 * @param other Instance to copy. 79 */ 80 protected InterpolatingMicrosphere2D(InterpolatingMicrosphere2D other) { 81 super(other); 82 } 83 84 /** 85 * Perform a copy. 86 * 87 * @return a copy of this instance. 88 */ 89 @Override 90 public InterpolatingMicrosphere2D copy() { 91 return new InterpolatingMicrosphere2D(this); 92 } 93 }