📄 datapoints.java
字号:
int maxsize = 0; double[] xval = null; double[] yval = null; BiNormal bn = new BiNormal(); // initialize variables // xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; maxsize = 200; xval = new double[maxsize]; yval = new double[maxsize]; // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmin + (xmax - xmin) / 4.0, ymax - (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> first = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { first.addElement(new MyPoint(xval[i], yval[i])); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmax - (xmax - xmin) / 4.0, ymin + (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> second = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { second.addElement(new MyPoint(xval[i], yval[i])); } dset1 = first; dset2 = second; } /** * create a set of point that correspond to two rotated ellipses to * be displayed on the input canvas * * @param scale DisplayScale variable used for displaying */ public void setRotatedEllipses(DisplayScale scale) { // local variables // double xmax, xmin, ymax, ymin; int maxsize = 0; double[] xval = null; double[] yval = null; BiNormal bn = new BiNormal(); // initialize variables // xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; maxsize = 200; xval = new double[maxsize]; yval = new double[maxsize]; // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmin + (xmax - xmin) / 4.0, ymax - (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> first = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { first.addElement(new MyPoint(xval[i], yval[i])); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmax - (xmax - xmin) / 4.0, ymin + (ymax - ymin) / 4.0, xval, yval, ((0.017 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> second = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { second.addElement(new MyPoint(xval[i], yval[i])); } dset1 = first; dset2 = second; } /** * create a set of point that correspond to four ellipses to * be displayed on the input canvas * * @param scale DisplayScale variable used for displaying * */ public void setFourEllipses(DisplayScale scale) { // local variables // double xmax, xmin, ymax, ymin; int maxsize = 0; double[] xval = null; double[] yval = null; BiNormal bn = new BiNormal(); // initialize variables // xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; maxsize = 200; xval = new double[maxsize]; yval = new double[maxsize]; // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmax - (xmax - xmin) / 4.0, ymax - (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> first = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { first.addElement(new MyPoint(xval[i], yval[i])); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmin + (xmax - xmin) / 4.0, ymax - (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (ymax - ymin))/4) * (((ymax - ymin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> second = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { second.addElement(new MyPoint(xval[i], yval[i])); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmin + (xmax - xmin) / 4.0, ymin + (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> third = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { third.addElement(new MyPoint(xval[i], yval[i])); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmax - (xmax - xmin) / 4.0, ymin + (ymax - ymin) / 4.0, xval, yval, ((0.133 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.017 * (ymax - ymin)) / 4) * (((ymax - ymin)) / 4)); // format the point to be plotted on the screen // Vector<MyPoint> forth = new Vector<MyPoint>(maxsize); for (int i = 0; i < maxsize; i++) { forth.addElement(new MyPoint(xval[i], yval[i])); } dset1 = first; dset2 = second; dset3 = third; dset4 = forth; } /** * create a set of point that correspond a toroidal to * be displayed on the input canvas * * @param scale DisplayScale variable used for displaying * */ public void setToroidal(DisplayScale scale) { // declare variables // double xmax, xmin, ymax, ymin; Vector<MyPoint> torodial1; Vector<MyPoint> torodial2; int maxsize = 0; double[] xval = null; double[] yval = null; BiNormal bn = new BiNormal(); double angle = 0.0; double radius = 0.0; double x1 = 0.0; double y1 = 0.0; double ring_radius; double stddev_radius; int num_ring = 2000; // initialize variables // xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; maxsize = 400; xval = new double[maxsize]; yval = new double[maxsize]; torodial1 = new Vector<MyPoint>(50, 10); torodial2 = new Vector<MyPoint>(50, 10); ring_radius = 1.5 * ((ymax - ymin)) / 4; stddev_radius = 0.1 * ((ymax - ymin)) / 4; // make outside ring // for (int i = 1; i <= num_ring; i++) { // the angle is linearly distributed from 0 to 2 pi // angle = MathUtil.random.nextDouble() * 2 * Math.PI; radius = MathUtil.grand(ring_radius, stddev_radius); // set points // x1 = radius * Math.cos(angle); y1 = radius * Math.sin(angle); // plot the points // torodial2.addElement(new MyPoint(x1 + xmin + (xmax-xmin)/2.0, y1 + ymin + (ymax-ymin)/2.0)); } // generate the binormal gaussian random deviates // bn.gaussian( maxsize, xmin + (xmax - xmin) / 2.0, ymin + (ymax - ymin) / 2.0, xval, yval, ((0.033 * (xmax - xmin)) / 4) * (((xmax - xmin)) / 4), 0.0, 0.0, ((0.033 * (xmax - xmin)) / 4) * ((xmax - xmin) / 4)); // format the point to be plotted on the screen // for (int i = 0; i < maxsize; i++) { torodial1.addElement(new MyPoint(xval[i], yval[i])); } // initialize each torodial to each set // dset1 = torodial1; dset2 = torodial2; } /** * create a set of point that correspond a yin and yang symbol to * be displayed on the input canvas * * @param scale DisplayScale variable used for viewing * */ public void setYinYang(DisplayScale scale) { // declare variables // double xmax, xmin, ymax, ymin; Vector<MyPoint> Yin; Vector<MyPoint> Yang; double xpt = 0.0; double ypt = 0.0; double currPoints = 0; double maxPoints = 1000; double distance1 = 0.0; double distance2 = 0.0; double distance3 = 0.0; double radius1 = 0.0; double radius2 = 0.0; double stddev_center; // initialize variables // xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; stddev_center = 1.5 * (xmax - xmin) / 2; Yin = new Vector<MyPoint>(50, 10); Yang = new Vector<MyPoint>(50, 10); radius1 = 1.5 * (((xmax - xmin))/4); radius2 = 0.75 * (((xmax - xmin))/4); while (currPoints < maxPoints) { // generate points // xpt = MathUtil.grand(xmin + (xmax-xmin)/2.0, stddev_center); ypt = MathUtil.grand(ymin + (ymax-ymin)/2.0, stddev_center); // calculate radius for each generated point // distance1 = Math.sqrt( (xpt) * (xpt) + (ypt) * (ypt)); distance2 = Math.sqrt( (xpt) * (xpt) + (ypt + radius2) * (ypt + radius2)); distance3 = Math.sqrt( (xpt) * (xpt) + (ypt - radius2) * (ypt - radius2)); // decide where to plot each point // if (distance1 <= radius1) { if (xpt >= (0.0 - radius1) && xpt <= 0.0) { if ((distance1 <= radius1 || distance2 <= radius2) && distance3 > radius2) { Yin.addElement(new MyPoint(xpt, ypt)); currPoints++; } else { Yang.addElement(new MyPoint(xpt, ypt)); } } if (xpt > 0.0 && xpt <= radius1) { if ((distance1 <= radius1 || distance3 <= radius2) && distance2 > radius2) { Yang.addElement(new MyPoint(xpt, ypt)); currPoints++; } else { Yin.addElement(new MyPoint(xpt, ypt)); } } } } // set yin and yang to each set dset1 = Yang; dset2 = Yin; } /** * Converts an instance of Point to an instance of MyPoint containing the * cartesian x-y values * * @param jpoint Point variable used to set MyPoint * @param panelWidth Width of viewing panel * @param panelHeight Height of viewing panel * @param scale DisplayScale variable used for viewing * * @return MyPoint convertion * */ static public MyPoint convertPoint(Point jpoint, int panelWidth, int panelHeight, DisplayScale scale) { double xmax, xmin, ymax, ymin; xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; return new MyPoint( MathUtil.SetDecimal((((double)jpoint.x/panelWidth) * (xmax-xmin)) + xmin, 8), MathUtil.SetDecimal((((panelHeight-(double)jpoint.y)/panelHeight) * (ymax-ymin)) + ymin, 8)); } /** * Converts a vector of Points to a vector of MyPoints containing the * cartesian x-y values * * @param jset Vector of points to be converted * @param panelWidth Width of viewing panel * @param panelHeight Height of viewing panel * @return Vector of MyPoints converted * */ static public Vector<MyPoint> convertPoints(Vector<Point> jset, int panelWidth, int panelHeight, DisplayScale scale) { Vector<MyPoint> dset = new Vector<MyPoint>(); for (int i = 1; i <= jset.size(); i++) { dset.addElement(convertPoint((Point)jset.elementAt(i), panelWidth, panelHeight, scale)); } return dset; } /** * Converts an instance of MyPoint to an instance of Point * * @param dpoint MyPoint to be converted * @param panelWidth Width of panel for viewing * @param panelHeight Width of panel for viewing * @return Point type converted from MyPoint type * */ static public Point convertMyPoint(MyPoint dpoint, int panelWidth, int panelHeight, DisplayScale scale) { double xmax, xmin, ymax, ymin; double xpt,ypt; Point jpoint; xmax = scale.xmax; xmin = scale.xmin; ymax = scale.ymax; ymin = scale.ymin; xpt = (panelWidth * (dpoint.x - xmin))/(xmax - xmin); ypt = panelHeight - (((dpoint.y-ymin) * panelHeight)/(ymax - ymin)); jpoint = new Point((int)xpt, (int)ypt); return jpoint; } /** * Converts a Vector of MyPoints to a Vector of points that correspond to * Java coordinates. * * @param dset Vector of MyPoints to be converted to Vector of Points * @param panelWidth Width of panel for viewing * @param panelHeight Height of panel for viewing * @return Vector of Points converted from MyPoints * */ static public Vector<Point> convertMyPoints (Vector<MyPoint> dset, int panelWidth, int panelHeight, DisplayScale scale) { double xpt, ypt; Vector<Point> jset = new Vector<Point>(); MyPoint dpoint = new MyPoint(); for (int i = 0; i < dset.size(); i++) { jset.addElement(convertMyPoint((MyPoint)dset.elementAt(i), panelWidth, panelHeight, scale)); } return jset; } /** * sets the gaussian values * * @param points number of points * @param cov11 double value of covariance11 * @param cov12 double value of covariance12 * @param cov21 double value of covariance21 * @param cov22 double value of covariance22 * */ public void setDrawGaussValues(int points, double cov11, double cov12, double cov21, double cov22) { this.points = points; this.cov11 = cov11; this.cov12 = cov12; this.cov21 = cov21; this.cov22 = cov22; } /** * sets the gaussian values * * @param color_dset1 color for data set 1 * @param color_dset2 color for data set 2 * @param color_dset3 color for data set 3 * @param color_dset4 color for data set 4 */ public void setColors(Color color_dset1, Color color_dset2, Color color_dset3, Color color_dset4) { this.color_dset1 = color_dset1; this.color_dset2 = color_dset2; this.color_dset3 = color_dset3; this.color_dset4 = color_dset4; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -