source: ether_statistics/service/implementation/gov/noaa/pmel/util/LinearTransform.java @ 569

Last change on this file since 569 was 569, checked in by vmipsl, 12 years ago

Nouveau projet

File size: 3.9 KB
Line 
1/*
2 * $Id: LinearTransform.java,v 1.3 2002/12/03 16:35:50 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>LinearTransform</code> defines a liniear 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.3 $, $Date: 2002/12/03 16:35:50 $
27 */
28public class LinearTransform implements Transform {
29        Range2D mPhysRange = null;
30        Range2D mUserRange = null;
31        double mPUSlope, mPUYintercept;
32        double mUPSlope, mUPYintercept;
33
34        public LinearTransform(double p1, double p2, double u1, double u2) {
35                setRangeP(p1, p2);
36                setRangeU(u1, u2);
37                computeTransforms();
38        }
39
40        public LinearTransform(Range2D prange, Range2D urange) {
41                setRangeP(prange);
42                setRangeU(urange);
43                computeTransforms();
44        }
45
46        public LinearTransform() {
47        }
48       
49        /**
50        * Set physical coordinate range.
51        *
52        * @param p1 minimum value, physical coordinates
53        * @param p2 maximum value, physical coordinates
54        * @see LinearTransform
55        **/
56        public void setRangeP(double p1,double p2) {
57                mPhysRange = new Range2D(p1, p2);
58        }
59
60        /**
61        * Set physical coordinate range.
62        *
63        * @param prange physcial coordinate range
64        * @see Range2D
65        * @see LinearTransform
66        **/
67        public void setRangeP(Range2D prange) {
68                mPhysRange = null;
69                mPhysRange = new Range2D();
70                mPhysRange.add(prange);
71        }
72
73        /**
74        * Get the physical coordinate range.
75        *
76        * @return physcial coordinate range
77        * @see Range2D
78        **/
79        public Range2D getRangeP() {
80                return mPhysRange;
81        }
82
83        /**
84        * Set the user coordinate range for double values.
85        *
86        * @param u1 minimum value, user coordinates
87        * @param u2 maximum value, user coordinates
88        * @see LinearTransform
89        **/
90        public void setRangeU(double u1,double u2) {
91                mUserRange = new Range2D(u1, u2);
92        }
93
94        /**
95        * Set the user coordinate range for double values.
96        *
97        * @param urange user coordinate range
98        * @see Range2D
99        * @see LinearTransform
100        **/
101        public void setRangeU(Range2D urange) {
102                mUserRange = null;
103                mUserRange = new Range2D();
104                mUserRange.add(urange);
105                computeTransforms();
106        }
107
108        /**
109        * Get the user coordinate range for double values.
110        *
111        * @return user range
112        * @see Range2D
113        **/
114        public Range2D getRangeU() {
115                return mUserRange;
116        }
117
118        /**
119        * Transform from user to physical coordinates.
120        *
121        * @param u user value
122        * @return physical value
123        */
124        public double getTransP(double u) {
125                return (mUPSlope * u) + mUPYintercept;
126        }
127
128        /**
129        * Transform from physical to user coordinates.
130        *
131        * @param p physical value
132        * @return user value
133        */
134        public double getTransU(double p) {
135                return (mPUSlope *p) + mPUYintercept;
136        }
137
138        /**
139        * Add listener for changes to transform properties.
140        */
141        public void addPropertyChangeListener(PropertyChangeListener listener) {
142
143        }
144
145        public void removePropertyChangeListener(PropertyChangeListener listener) {
146
147        }
148       
149        public void computeTransforms() {
150                computePULine();
151                computeUPLine();
152        }
153       
154        private void computePULine() {
155                double denom = mPhysRange.start - mPhysRange.end;
156                double num = mUserRange.start - mUserRange.end;
157                mPUSlope = num/denom;
158                mPUYintercept = mUserRange.start - (mPUSlope * mPhysRange.start);
159        }
160       
161        private void computeUPLine() {
162                double num = mPhysRange.start - mPhysRange.end;
163                double denom = mUserRange.start - mUserRange.end;
164                mUPSlope = num/denom;
165                mUPYintercept = mPhysRange.start - (mPUSlope * mUserRange.start);
166        }
167}
168
Note: See TracBrowser for help on using the repository browser.