package com.hb.proj.diagram.diagnose; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Line2D; import java.util.List; /** * 功图绘制,用于功图诊断,作为被诊断对象、标准功图 * 只需要闭合曲线,其他不需要绘制 * 功图诊断时,最好标准功图和待诊断功图出自同一绘制方法、同大小 * @author cwen * */ public class DiagramRender { private Color canvasColor; private int canvasWidth; private int canvasHeight; private int originX ; //原点x值 private int originY ; //原点y值 private int xAxisEnd; private int yAxisEnd; private double xMinValue; private double yMinValue; private double xMaxValue; private double yMaxValue; private double xRatio; private double yRatio; public DiagramRender(){ this(360,180); } public DiagramRender(int canvasWidth,int canvasHeight){ this.canvasWidth=canvasWidth; this.canvasHeight=canvasHeight; this.canvasColor=new Color(255,255,255); this.originX=10; this.originY=canvasHeight-10; this.xAxisEnd=canvasWidth-10; this.yAxisEnd=10; this.xMaxValue=3; this.xMinValue=0; this.yMaxValue=50; this.yMinValue=0; } public void draw(Graphics2D g2,List disps,List oths,double stroke,double maxOth,double minOth) { this.xMinValue=0; this.xMaxValue=Math.ceil(stroke); this.yMinValue=Math.floor(minOth); //定格画,避免井的个体特性影响相似性判断,相当于各类图缩放在一个区域内 this.yMaxValue=Math.ceil(maxOth); this.xRatio=(this.xAxisEnd-this.originX)/(this.xMaxValue-this.xMinValue); this.yRatio=(this.originY-this.yAxisEnd)/(this.yMaxValue-this.yMinValue); this.drawCanvas(g2); //this.drawCoordinate(g2); this.drawCurve(g2, disps, oths); } /** * 绘制画布 * @param g2 */ public void drawCanvas(Graphics2D g2){ g2.setColor(this.canvasColor); g2.fillRect(0, 0, this.canvasWidth, this.canvasHeight); } /** * 简易坐标轴 * @param g2 */ public void drawCoordinate(Graphics2D g2) { g2.setStroke(new BasicStroke(1)); g2.setColor(new Color(212,212,212)); g2.drawLine(this.originX, this.originY, this.originX, this.yAxisEnd); //y 轴 g2.drawLine(this.xAxisEnd, this.originY, this.xAxisEnd, this.yAxisEnd); //y border g2.drawLine(this.originX, this.yAxisEnd, this.xAxisEnd, this.yAxisEnd); //x border g2.drawLine(this.originX, this.originY,this.xAxisEnd,this.originY); //x bottom-border int yGirdCount=5; double yGridDivide=(this.originY-this.yAxisEnd)/yGirdCount; double tempy=0; for(int i=1;i disps,List oths) { g2.setStroke(new BasicStroke(1)); g2.setPaint(new Color(0,0,0)); double ptx=getX(disps.get(0)),pty=getY(oths.get(0)); double nptx=0,npty=0; for(int i=1,len=disps.size(),len2=oths.size();i