1 /*
2 * Licensed to the Hipparchus project 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 Hipparchus project 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 package org.hipparchus.samples.complex;
19
20 import org.hipparchus.complex.Complex;
21 import org.hipparchus.util.FastMath;
22 import org.hipparchus.util.MathUtils;
23
24 /** Base class for domain coloring.
25 * <p>All methods have the following features:</p>
26 * <ul>
27 * <li>hue represents phase (red for 0, then orange, yellow, green,
28 * blue at π, indigo, violet and back to red)</li>
29 * <li>saturation is constant</li>
30 * </ul>
31 * <p>Their differences lie on what value represents.</p>
32 */
33 public abstract class DomainColoring {
34
35 /** Constant saturation. */
36 private final double saturation;
37
38 /** Simple constructor.
39 * @param saturation constant saturation
40 */
41 protected DomainColoring(final double saturation) {
42 this.saturation = saturation;
43 }
44
45 /** Continuous hue.
46 * @param z complex value
47 * @return continuous hue
48 */
49 public double hue(final Complex z) {
50 final double phase = FastMath.PI + FastMath.atan2(-z.getImaginaryPart(), -z.getRealPart());
51 return phase / MathUtils.TWO_PI;
52 }
53
54 /** Get saturation for a complex value.
55 * @param z complex value
56 * @return saturation
57 */
58 public double saturation(Complex z) {
59 return saturation;
60 }
61
62 /** Get value for a complex value.
63 * @param z complex value
64 * @return value
65 */
66 protected abstract double value(Complex z);
67
68 }