📄 interpolate.java,v
字号:
head 1.5;access;symbols;locks; strict;comment @# @;1.5date 2005.06.10.18.45.02; author rirwin; state Exp;branches;next 1.4;1.4date 2005.05.24.16.28.07; author rirwin; state Exp;branches;next 1.3;1.3date 2005.03.12.00.24.17; author patil; state Exp;branches;next 1.2;1.2date 2005.01.19.21.41.24; author patil; state Exp;branches;next 1.1;1.1date 2004.12.28.00.04.32; author patil; state Exp;branches;next ;desc@@1.5log@Establishing RCS version.@text@/** * file: interpolate.java * *last edited: Ryan Irwin *///class imports//import java.awt.*;import java.util.*;import javax.swing.*;import java.lang.* ;/** * Interpolate class * */public class interpolate{ // public members double m , c; Vector<MyPoint> iset = new Vector<MyPoint>(40, 20); // pulic methods /** * Interpolates * * @@param v input vector * @@return output vector */ public Vector<MyPoint> interpol(Vector<MyPoint> v) { // dummy variables for internal use // // size = size of the input data set // p, q, r, t = dummmy points // int size, l = 0; double a, sample, d, temp ; // MyPoint p, q, t; MyPoint r = new MyPoint(); MyPoint p = new MyPoint(); MyPoint q = new MyPoint(); MyPoint t = new MyPoint(); // the size of the data points // size = v.size(); p =(MyPoint)v.lastElement(); q =(MyPoint)v.firstElement(); // do not know, but the code works with this...? // display the input data points // for checking purpose // // System.out.println("input data points "+ v); /* if(p.x < 0 && q.x < 0) d = Math.abs(q.x) - Math.abs(p.x); else if (p.x > 0 && q.x > 0) d = Math.abs(p.x) - Math.abs(q.x); else d = Math.abs(p.x) + Math.abs(q.x);*/ iset.removeAllElements(); // total time interval of the data points calculated // d = p.x - q.x; // check purpose, displaying the time interval // // System.out.println("total time interval = " + d); // time step calculation // sample = MathUtil.SetDecimal(d/(size-1), 2) ; // Check up of the values calculated // time step and first new point // // System.out.println(" Time Step = " + sample); // System.out.println( // " First New Point is the First (USER-Given) data point! "); // System.out.println(" First New Point > " + q.x); // iset holds new data points - interpolated values // First value added // iset.addElement(new MyPoint(q) ); // Next New Time value calculated and displayed temp = q.x ; r.x = sample + temp; MathUtil.SetDecimal(r.x, 2); // System.out.println(" First New Point > " + q.x); // System.out.println( // "Time T_ONE @@ which amplitude is to be calculated " + r.x); while (r.x <= p.x) { for(int j = 1; j < v.size(); j++) { t = ( MyPoint) v.elementAt(j); // the New Interpolated amplitude will be calculated // for the two points within which the time intervals // lies, Hence, the condition check // if ((r.x <= t.x) && (r.x >= ((MyPoint)v.elementAt(j-1)).x)) { slope((MyPoint)v.elementAt(j-1),t); // System.out.println( // "slope = " + m + " y_intercept = ," + c); // amplitude calculation r.y = 0.0 ; r.y = MathUtil.SetDecimal(( m * r.x + c), 2) ; // MathUtil.SetDecimal(r.y, 2); // System.out.println( // "Time Instant (x-value) > " + r.x); // System.out.println( // "Amplitude (y-value) > " + r.y); // New value appended to the array // iset.addElement(new MyPoint(r)); // System.out.println( // "The Interpolated values till now " + iset); // System.out.println("hi" + r.x + "," + r.y); l++; // mypoint and store in vector break; } } // q.x = 0.0; // q.y = 0.0; // q.x = r.x ; // q.y = r.y; r.x = r.x + sample; MathUtil.SetDecimal(r.x, 2); } iset.addElement(new MyPoint(p)); // System.out.println("input data points " + iset); return iset ; } /** * Sets the slope variable m and c * * @@param u Point one * @@param v Point two */ public void slope(MyPoint u , MyPoint v) { // double m , c ; // System.out.println(" v.y > " + v.y + "v.x > " + v.x); // System.out.println(" u.y > " + u.y + "u.x > " + u.x); m = (v.y - u.y)/(v.x-u.x) ; c = u.y - m*u.x ; MathUtil.SetDecimal(m,2); MathUtil.SetDecimal(c,2); } }@1.4log@Fixed javadoc comments.@text@d7 1d24 1a24 1 Vector iset = new Vector(40, 20) ; d34 1a34 1 public Vector interpol(Vector v)@1.3log@Changed comments to Java Documentation.@text@d1 5d7 2d15 4a18 1d27 6d157 6a162 1 @1.2log@All the debug statements commented out@text@d24 3a26 3 int size,l = 0; double a,sample,d,temp ; //MyPoint p, q, t;d31 1d37 1a38 1d42 1a42 1 //System.out.println("input data points "+ v); d45 4a48 4 if(p.x<0 && q.x<0) d = Math.abs(q.x)-Math.abs(p.x); else if (p.x>0 && q.x>0) d = Math.abs(p.x)-Math.abs(q.x);d50 1a50 1 d = Math.abs(p.x)+Math.abs(q.x);*/d60 1a60 1 //System.out.println("total time interval = " + d);d69 4a72 3 //System.out.println(" Time Step = " + sample); //System.out.println(" First New Point is the First (USER-Given) data point! "); //System.out.println(" First New Point > " + q.x);d83 4a86 3 MathUtil.SetDecimal(r.x,2); //System.out.println(" First New Point > " + q.x); //System.out.println("Time T_ONE @@ which amplitude is to be calculated " + r.x);d89 45a133 39 { for(int j = 1; j < v.size(); j++) { // t = ( MyPoint) v.elementAt(j); // the New Interpolated amplitude will be calculated // for the two points within which the time intervals // lies, Hence, the condition check // if ((r.x <= t.x) && (r.x >= ((MyPoint)v.elementAt(j-1)).x)) { slope((MyPoint)v.elementAt(j-1),t); //System.out.println("slope = " + m + " y_intercept = ," + c); // amplitude calculation r.y = 0.0 ; r.y = MathUtil.SetDecimal(( m * r.x + c), 2) ; // MathUtil.SetDecimal(r.y,2); //System.out.println("Time Instant (x-value) > " + r.x); //System.out.println("Amplitude (y-value) > " + r.y); // New value appended to the array // iset.addElement(new MyPoint(r)); //System.out.println("The Interpolated values till now " + iset); //System.out.println("hi"+r.x+","+r.y); l++; // mypoint and store in vector break; } } // q.x = 0.0; // q.y = 0.0; // q.x = r.x ; // q.y = r.y; r.x = r.x + sample; MathUtil.SetDecimal(r.x,2); }d135 1a135 1 //System.out.println("input data points "+iset);d142 13a154 15 public void slope(MyPoint u , MyPoint v) { // double m , c ; //System.out.println("v.y > "+v.y+"v.x > "+v.x); //System.out.println("u.y > "+u.y+"u.x > "+u.x); m = (v.y - u.y)/(v.x-u.x) ; c = u.y - m*u.x ; MathUtil.SetDecimal(m,2); MathUtil.SetDecimal(c,2); }d157 2a158 3@1.1log@Initial revision@text@d41 1a41 1 System.out.println("input data points "+ v); d59 1a59 1 System.out.println("total time interval = " + d);d68 3a70 3 System.out.println(" Time Step = " + sample); System.out.println(" First New Point is the First (USER-Given) data point! "); System.out.println(" First New Point > " + q.x);d82 2a83 2 System.out.println(" First New Point > " + q.x); System.out.println("Time T_ONE @@ which amplitude is to be calculated " + r.x);d99 1a99 1 System.out.println("slope = " + m + " y_intercept = ," + c);d105 2a106 2 System.out.println("Time Instant (x-value) > " + r.x); System.out.println("Amplitude (y-value) > " + r.y);d110 1a110 1 System.out.println("The Interpolated values till now " + iset);d126 1a126 1 System.out.println("input data points "+iset);d137 2a138 2 System.out.println("v.y > "+v.y+"v.x > "+v.x); System.out.println("u.y > "+u.y+"u.x > "+u.x);d150 2@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -