📄 graficovoz.java
字号:
/*
* GraficoVoz.java
*
* Created on 16 de enero de 2008, 08:17 PM
*/
package rah;
/**
*
* @author JhonFranko
*/
import java.awt.*;
import javax.swing.*;
public class GraficoVoz extends javax.swing.JPanel
{
/** Creates new form GraficoVoz */
private double[] datosVoz;
private int alto=0,ancho=0;
public boolean graficarOnda=false;
private Image imagen;
private Graphics pantalla;
public boolean graficar=true;
public double factorE;
public double factorEX;
public double factorEY;
public double tyEje;
public int intervalo;
public double pPitch=0;
public boolean graficarPPitch=false;
public GraficoVoz()
{
datosVoz=null;
//initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents()
{
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
public void setDxVoz(double[] dxVoz)
{
this.datosVoz=dxVoz;
}
public void anchoT(int anch)
{
this.ancho=anch;
}
public void altoT(int alt)
{
this.alto=alt;
}
public void update(Graphics g)
{
paint(g);
}
//**********************************************************************************************
public double[] cambiarCoordenadasDispositivo(double[] cp,int wV, int hV)
{
double[] p=new double[2];
double wPV=ancho/2;
double hPV=alto/2;
p[0]=Math.round(((cp[0]*wPV)/wV) + wPV);
p[1]=Math.round(hPV-((cp[1]*hPV)/hV)) ;
return p;
}
public double P_Lagrange(double x,int n,double[] Puntos)
{
double y=0;
int cont=intervalo;
for (int k=0;k<n-cont;k=k+cont)
{
double ln=1;
for (int i=0;i<n-cont;i=i+cont)
{
if(i!=k)
{
ln=ln*((x-i)/(k-i));
}
}
y=y+(ln*Puntos[k]);
}
return y;
}
public void graficarLineas(Graphics g)
{
//*********************************************
double[] puntoP=new double[2]; /*punto proyectado*/
double[] punto2D=new double[2]; /*punto en coordenadas del dispositivo*/
int xi=0,xf=0,yi=0,yf=0,i=0;
//*********************************************
double[] MCoordP=getVDxVoz();
int c=MCoordP.length;
int cont=intervalo;
//int c=MCoordP[0].length;
for( i=0;i<c-cont;i=i+cont)
{
puntoP[0]=i*factorEX;
puntoP[1]=MCoordP[i]*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xi=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yi=(int)punto2D[1]-(int)tyEje;
puntoP[0]=(i+cont)*factorEX;
puntoP[1]=MCoordP[i+cont]*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xf=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yf=(int)punto2D[1]-(int)tyEje;
g.setColor(Color.green);
g.drawLine(xi,yi,xf,yf);
}
}
public void graficarPitch(Graphics g)
{
double[] puntoP=new double[2]; /*punto proyectado*/
double[] punto2D=new double[2]; /*punto en coordenadas del dispositivo*/
int xi=0,xf=0,yi=0,yf=0,i=0;
double x=0,y=0;
//*********************************************
for( x=0;x<datosVoz.length-(int)pPitch;x=x+(int)pPitch)
{
puntoP[0]=x*factorEX;
puntoP[1]=4000*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xi=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yi=(int)punto2D[1];
puntoP[0]=x*factorEX;
puntoP[1]=-4000*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xf=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yf=(int)punto2D[1];
g.setColor(Color.white);
g.drawLine(xi,yi,xf,yf);
}
}
public void graficarFuncion(Graphics g)
{
//*********************************************
double[] puntoP=new double[2]; /*punto proyectado*/
double[] punto2D=new double[2]; /*punto en coordenadas del dispositivo*/
int xi=0,xf=0,yi=0,yf=0,i=0;
double x=0,y=0;
//*********************************************
double[] MCoordP=getVDxVoz();
int c=MCoordP.length;
// System.out.println(" longitud del arreglo a dibujar "+c);
int cont=intervalo;
// System.out.println(" intervalo de puntos "+cont);
//******************************************************************
x=0;
y=P_Lagrange(x,c,MCoordP);
puntoP[0]=x*factorEX;
puntoP[1]=y*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xi=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yi=(int)punto2D[1]-(int)tyEje;
// System.out.println("punto a graficar "+xi+" "+yi);
//******************************************************************
for( x=0;x<c-cont;x=x+cont)
{
y=P_Lagrange(x,c,MCoordP);
puntoP[0]=x*factorEX;
puntoP[1]=y*factorEY;
punto2D=cambiarCoordenadasDispositivo(puntoP,ancho,alto);
xf=(int)(punto2D[0]+30)-(int)(ancho/2.0);
yf=(int)punto2D[1]-(int)tyEje;
g.setColor(Color.green);
g.drawLine(xi,yi,xf,yf);
xi=xf;
yi=yf;
}
}
public void borrar()
{
datosVoz=null;
graficar=false;
graficarOnda=false;
graficarPPitch=false;
}
public void paint(Graphics g)
{
imagen = this.createImage(ancho, alto);
pantalla = imagen.getGraphics();
//System.out.println(graficar+" "+graficarOnda);
if(graficar==false)
{
pantalla.clearRect(0,0,ancho,alto);
pantalla.fillRect(0,0,ancho,alto);
pantalla.setColor(Color.BLUE);
pantalla.drawLine(30,0,30,alto);
pantalla.drawLine(0,alto/2-(int)tyEje,ancho,alto/2-(int)tyEje);
}
else
{
pantalla.fillRect(0,0,ancho,alto);
pantalla.setColor(Color.BLUE);
pantalla.drawLine(30,0,30,alto);
pantalla.drawLine(0,alto/2-(int)tyEje,ancho,alto/2-(int)tyEje);
//*********************************
if(graficarOnda==true)
{
graficarLineas(pantalla);
//graficarFuncion(pantalla);
if(graficarPPitch==true)
graficarPitch(pantalla);
}
}
g.drawImage(imagen, 0, 0,this);
}
public double[] getVDxVoz()
{
return this.datosVoz;
}
public void setFactorE(double f)
{
this.factorE=f;
}
public void setFactorEX(double f)
{
this.factorEX=f;
}
public void setFactorEY(double f)
{
this.factorEY=f;
}
public void setIntervalo(int i)
{
this.intervalo=i;
}
public void setPeriodoPitch(double p)
{
this.pPitch=p;
}
public void setTraslacionYEje(double t)
{
this.tyEje=t;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -