source: ether_megapoli/trunk/service/implementation/gov2/noaa/pmel/util/ExponentialTransformDown.java @ 192

Last change on this file since 192 was 192, checked in by vmipsl, 13 years ago

Servlet _ Contour en cours _ package gov2

File size: 4.4 KB
Line 
1/*
2 * $Id: ExponentialTransformDown.java,v 1.1 2002/12/04 01:27:38 oz Exp $
3 *
4 * This software is provided by NOAA for full, free and open release.  It is
5 * understood by the recipient/user that NOAA assumes no liability for any
6 * errors contained in the code.  Although this software is released without
7 * conditions or restrictions in its use, it is expected that appropriate
8 * credit be given to its author and to the National Oceanic and Atmospheric
9 * Administration should the software be included by the recipient as an
10 * element in other product development.
11 */
12 
13package gov.noaa.pmel.util;
14
15import java.beans.PropertyChangeListener;
16import gov.noaa.pmel.util.Range2D;
17import gov.noaa.pmel.sgt.Transform;
18 
19/**
20 * <code>ExponentialTransformUp</code> defines a exponential transformations between
21 * user and physical coordinates defined between two end points.
22 *
23 * @see AxisTransform
24 *
25 * @author Donald Denbo
26 * @version $Revision: 1.1 $, $Date: 2002/12/04 01:27:38 $
27 */
28public class ExponentialTransformDown implements Transform {
29        Range2D mPhysRange = null;
30        Range2D mUserRange = null;
31        //double a = 0.46487;
32        //double b = 1.7563;
33        //double c = -2.8931;
34        //double d = 2.6001;
35       
36        double a = 0.82605;
37        double b = -2.3006;
38        double c = 2.4729;
39
40        public ExponentialTransformDown(double p1, double p2, double u1, double u2) {
41                setRangeP(p1, p2);
42                setRangeU(u1, u2);
43        }
44
45        public ExponentialTransformDown(Range2D prange, Range2D urange) {
46                setRangeP(prange);
47                setRangeU(urange);
48        }
49
50        public ExponentialTransformDown() {
51        }
52       
53        /**
54        * Set physical coordinate range.
55        *
56        * @param p1 minimum value, physical coordinates
57        * @param p2 maximum value, physical coordinates
58        * @see LinearTransform
59        **/
60        public void setRangeP(double p1,double p2) {
61                mPhysRange = new Range2D(p1, p2);
62        }
63
64        /**
65        * Set physical coordinate range.
66        *
67        * @param prange physcial coordinate range
68        * @see Range2D
69        * @see LinearTransform
70        **/
71        public void setRangeP(Range2D prange) {
72                mPhysRange = null;
73                mPhysRange = new Range2D();
74                mPhysRange.add(prange);
75        }
76
77        /**
78        * Get the physical coordinate range.
79        *
80        * @return physcial coordinate range
81        * @see Range2D
82        **/
83        public Range2D getRangeP() {
84                return mPhysRange;
85        }
86
87        /**
88        * Set the user coordinate range for double values.
89        *
90        * @param u1 minimum value, user coordinates
91        * @param u2 maximum value, user coordinates
92        * @see LinearTransform
93        **/
94        public void setRangeU(double u1,double u2) {
95                mUserRange = new Range2D(u1, u2);
96        }
97
98        /**
99        * Set the user coordinate range for double values.
100        *
101        * @param urange user coordinate range
102        * @see Range2D
103        * @see LinearTransform
104        **/
105        public void setRangeU(Range2D urange) {
106                mUserRange = null;
107                mUserRange = new Range2D();
108                mUserRange.add(urange);
109        }
110
111        /**
112        * Get the user coordinate range for double values.
113        *
114        * @return user range
115        * @see Range2D
116        **/
117        public Range2D getRangeU() {
118                return mUserRange;
119        }
120
121        /**
122        * Transform from user to physical coordinates.
123        *
124        * @param u user value
125        * @return physical value
126        */
127        public double getTransP(double u) {
128                double retVal = 0.0;
129                // first have to find u in the normalized range of the y axis
130                double y = (u - mUserRange.start)/(mUserRange.end - mUserRange.start);
131               
132                // now iterate to find solution
133                double x = 0.5;
134                double inc = 0.0001;
135                double eps = 0.001;
136                int cnt = 0;
137                while (true) {
138                        //double tstVal = d * x + c * (x * x) + b * (x * x * x) + a * (x * x * x * x);
139                        double tstVal = c * x + b * (x * x) + a * (x * x * x);
140                        if (Math.abs(tstVal - y) < eps) {
141                                retVal = x;
142                                break;
143                        }
144                        else {
145                                if (tstVal > y)
146                                        x -= inc;
147                                else
148                                        x += inc;
149                        }
150                        cnt++;
151                }
152                //System.out.println("iter count = " + cnt);
153               
154                // scale the x value back to the unnormalized range
155                retVal = mPhysRange.start + x * (mPhysRange.end - mPhysRange.start);
156                return retVal;
157        }
158
159        /**
160        * Transform from physical to user coordinates.
161        *
162        * @param p physical value
163        * @return user value
164        */
165        public double getTransU(double p) {
166                double retVal = 0.0;
167                double x = (p - mPhysRange.start)/(mPhysRange.end - mPhysRange.start);
168                //double y = d * x + c * (x * x) + b * (x * x * x) + a * (x * x * x * x);
169                double y = c * x + b * (x * x) + a * (x * x * x);
170                retVal = mUserRange.start + y * (mUserRange.end - mUserRange.start);
171                return retVal;
172        }
173
174        /**
175        * Add listener for changes to transform properties.
176        */
177        public void addPropertyChangeListener(PropertyChangeListener listener) {
178
179        }
180
181        public void removePropertyChangeListener(PropertyChangeListener listener) {
182
183        }
184}
185
Note: See TracBrowser for help on using the repository browser.