import java.io.*;
import javax.swing.*;


public class HT_2DLTE
{
    double x[];
    double y[];
    double A;
    double N[];
    double a[],b[],c[];
	public HT_2DLTE(double xi[],double yi[])
    {for(int i=0;i<3;i++) {x[i]=xi[i];y[i]=yi[i];}
    double d[][]={{1,x[0],y[0]},{1,x[1],y[1]},{1,x[2],y[2]}};
    A=0.5*determinant(d);
    a[0]=x[1]*y[2]-x[2]*y[1];
    a[1]=x[2]*y[0]-x[0]*y[2];
    a[2]=x[0]*y[1]-x[1]*y[0];
    b[0]=y[1]-y[2];
    b[1]=y[2]-y[0];
    b[2]=y[0]-y[1];
    c[0]=x[2]-x[1];
    c[1]=x[0]-x[2];
    c[2]=x[1]-x[0];
    }
    public double[] N(double x,double y)
    {   double n[]=new double[3];
	    for(int i=0;i<3;i++)
	    {n[i]=0.5*A*(a[i]+b[i]*x+c[i]*y);}
    return n;
	}  
	 
    public double T(double Ti[],double x,double y)
    {   double N[]=N(x,y);
        double TT=0;
	    for(int i=0;i<3;i++)
	    {TT+=N[i]*Ti[i];}
    return TT;
	}
	  
public static double determinant(double a[][])
{
//determinant of a matrix
int n=a.length;
int indx[]=new int[n];
int d[]={1};
double e;
double b[][]=new double[n][n];
b=LU(a,indx,d);
e=d[0];
for(int i=0;i<n;i++)
  e=e*b[i][i];
return e;
}  //end of det

public static double[][] LU(double c[][],int indx[],int d[])
{
//returns LU decomposition of matrix c and index indx
double a[][];
int n=c.length;
a=new double[n][n];
double vv[];
vv=new double[n];
double sum,dum,big,temp;
int i,j,k;
int imax;
int nmax=100;
double tiny=1.0e-40;
imax=0;
for(i=1;i<=n;i++)
{
  for(j=1;j<=n;j++)
     a[i-1][j-1]=c[i-1][j-1];
}
d[0]=1;
for(i=1;i<=n;i++)
  {
  big=0.0;
  for(j=1;j<=n;j++)
    {
    if(Math.abs(a[i-1][j-1])>big) big=Math.abs(a[i-1][j-1]);
    }
  if(big==0) {System.out.println("singular matrix");return a;}
  vv[i-1]=1.0/big;
  }
for(j=1;j<=n;j++)
{
  for(i=1;i<j;i++)
    {
      sum=a[i-1][j-1];
      for(k=1;k<i;k++)
	{
	  sum-=a[i-1][k-1]*a[k-1][j-1];
	}
    a[i-1][j-1]=sum;
    }
  big=0;
  for(i=j;i<=n;i++)
    {
    sum=a[i-1][j-1];
    for(k=1;k<j;k++)
      {
      sum-=a[i-1][k-1]*a[k-1][j-1];
      }
    a[i-1][j-1]=sum;
    dum=vv[i-1]*Math.abs(sum);
    if(dum>=big)
      {
      imax=i;
      big=dum;
      }
    } //end of i=0
if(j != imax)
    {
    for(k=1;k<=n;k++)
      {
      dum=a[imax-1][k-1];
      a[imax-1][k-1]=a[j-1][k-1];
      a[j-1][k-1]=dum;
      }
    d[0]=-d[0];
    vv[imax-1]=vv[j-1];
    } //end of if
indx[j-1]=imax;
if(a[j-1][j-1]==0) a[j-1][j-1]=tiny;
if(j!=n)
  {
  dum=1.0/a[j-1][j-1];
  for(i=j+1;i<=n;i++)
    a[i-1][j-1]*=dum;
  }//endif
} //end for j=
return a;
}
	public static void main(String args[]) throws IOException
    {
    double x[]={0,4,0};
    double y[]={0,0,2.5};
    double T[]={50,70,100};
    HT_2DLTE z=new HT_2DLTE(x,y);
    double T1=T(T,2.0,1.0);
    String s="T = "+T1+"x= 2.0 y=1.0";
     JOptionPane.showMessageDialog(null,s," ",JOptionPane.PLAIN_MESSAGE);     
    }
}
