Question

PLEASE USE JAVA Write a program that draws the circumscribed circle (also known as the circumcircle)...

PLEASE USE JAVA

Write a program that draws the circumscribed circle (also known as the circumcircle) of a given triangle ABC; this circle passes through points A, B, and C. These points will be specified by the user by clicking the mouse button. Remember, the three perpendicular bisectors of the three edges of a triangle all pass through one point, the circumcenter, which is the center of the circumscribed circle.

Homework Answers

Answer #1
PLEASE UPVOTE 

import java.awt.*;
import static java.awt.Color.BLACK;
import static java.awt.Color.BLUE;
import static java.awt.Color.RED;
import java.awt.geom.*;
import static java.lang.Math.sqrt;
import javax.swing.JComponent;





public class graficadorTriangulo extends JComponent

{

     private double [] coordinatesX;
     private double [] coordinatesY;


    public graficadorTriangulo (double [] valoresX, double [] valoresY )
    {

        coordenadasX = valoresX;

        coordenadasY = valoresY;


    }



    public void paintComponent (Graphics g)

    {

        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        Point2D.Double click1Pun = new Point2D.Double(coordenadasX[0], coordenadasY[0]);
        Point2D.Double click2Pun = new Point2D.Double(coordenadasX[1], coordenadasY[1]);
        Point2D.Double click3Pun=  new Point2D.Double(coordenadasX[2], coordenadasY[2]);

        Point2D.Double click4Pun = new Point2D.Double(coordenadasX[0]/2, coordenadasY[0]/2);

        Point2D.Double click1Mitad = new Point2D.Double(coordenadasX[0]/2, coordenadasY[0]/2);
        Point2D.Double click2Mitad = new Point2D.Double(coordenadasX[1]/2, coordenadasY[1]/2);
        Point2D.Double click3Mitad = new Point2D.Double(coordenadasX[2]/2, coordenadasY[2]/2);





        Line2D.Double ladoaLin = new Line2D.Double(click1Pun, click2Pun); 
        Line2D.Double ladobLin = new Line2D.Double(click1Pun, click3Pun);
        Line2D.Double ladocLin = new Line2D.Double(click2Pun, click3Pun);


        double magnitudA = Math.sqrt( ( (coordenadasX[1] - coordenadasX[0] ) * ( coordenadasX[1]- coordenadasX[0] ) ) + ( ( coordenadasY[1] - coordenadasY[0] ) * ( coordenadasY[1] - coordenadasY[0] ) ) );
        double magnitudB = Math.sqrt( ( (coordenadasX[2] - coordenadasX[1] ) * ( coordenadasX[2]- coordenadasX[1] ) ) + ( ( coordenadasY[2] - coordenadasY[1] ) * ( coordenadasY[2] - coordenadasY[1] ) ) );
        double magnitudC = Math.sqrt( ( (coordenadasX[0] - coordenadasX[2] ) * ( coordenadasX[0]- coordenadasX[2] ) ) + ( ( coordenadasY[0] - coordenadasY[2] ) * ( coordenadasY[0] - coordenadasY[2] ) ) );


        double perimetroTriangulo = magnitudA + magnitudB + magnitudC;


        double incentroNumeradorx = ((coordenadasX[0]*magnitudB)+(coordenadasX[1]*magnitudC)+(coordenadasX[2]*magnitudA));
        double incentroNumeradory = ((coordenadasY[0]*magnitudB)+(coordenadasY[1]*magnitudC)+(coordenadasY[2]*magnitudA));


        double incentroX  = incentroNumeradorx/perimetroTriangulo;
        double incentroY  = incentroNumeradory/perimetroTriangulo;





        Point2D.Double incentroPunto = new Point2D.Double(incentroX,incentroY);

        double magnitudD = Math.sqrt( ( (incentroX - coordenadasX[3] ) * ( incentroX- coordenadasX[3] ) ) + ( ( incentroY - coordenadasY[3] ) * ( incentroY - coordenadasY[3] ) ) );




        Line2D.Double centroaLin = new Line2D.Double(incentroPunto, click1Pun);
        Line2D.Double centrobLin = new Line2D.Double(incentroPunto, click2Pun);
        Line2D.Double centrocLin = new Line2D.Double(incentroPunto, click3Pun);


        double magPerpendicularX = coordenadasX[1] - coordenadasX[0];
        double magPerpendicularY = coordenadasY[1] - coordenadasY[0];



        double magnitudBase = sqrt(magPerpendicularX*magPerpendicularX + magPerpendicularY*magPerpendicularY);
        magPerpendicularX /= magnitudBase;
        magPerpendicularY /= magnitudBase ;

        double lambda = (magPerpendicularX * (incentroX - coordenadasX[0])) + (magPerpendicularY * (incentroY - coordenadasY[0]));
        double x4 = (magPerpendicularX * lambda) + coordenadasX[0];
        double y4 = (magPerpendicularY * lambda) + coordenadasY[0];



        Point2D.Double pointPerpendicular=  new Point2D.Double(x4,y4);

        Line2D.Double ladoH = new Line2D.Double(incentroPunto, pointPerpendicular);


       double magnitudRadioincentro= Math.sqrt( ( (x4 - incentroX ) * ( x4- incentroX ) ) + ( ( y4 - incentroY ) * ( y4 - incentroY ) ) );

        int magnitudDiametroincentro = (int)magnitudRadioincentro *2;    




        int x = (int)incentroX;
        int y = (int)incentroY;

        int x2 = (int)incentroX;
        int y2 = (int)incentroY;


          x = x-(magnitudDiametroincentro/2);
          y = y-(magnitudDiametroincentro/2);  



         double magnitudRadiocircuncentro = (magnitudA*magnitudB*magnitudC)/
                                           Math.sqrt((magnitudA+magnitudB+magnitudC)*
                                                     ((magnitudB+magnitudC)-magnitudA)*
                                                     ((magnitudC+magnitudA)-magnitudB)*
                                                     ((magnitudA+magnitudB)-magnitudC));
         int magnitudDiametrocircuncentro= (int)magnitudRadiocircuncentro *2;

           x2 = x2-(magnitudDiametrocircuncentro/2);
           y2 = y2-(magnitudDiametrocircuncentro/2);  
           g.setColor(Color.GREEN);     
           g.drawOval(x,y,magnitudDiametroincentro,magnitudDiametroincentro);
           g.setColor(Color.GREEN); 
           g.drawOval(x2,y2,magnitudDiametrocircuncentro,magnitudDiametrocircuncentro);


          double angle = (double) Math.toDegrees(Math.atan2( coordenadasX[1] -  coordenadasX[0],  coordenadasY[1] -  coordenadasY[0]));

    if(angle < 0){
        angle += 360;



    }
        System.out.println("***********" + angle);
       g.setColor(Color.BLACK);
        g2.draw(ladoaLin);
        g2.draw(ladobLin);
        g2.draw(ladocLin);

        g.setColor(Color.BLUE);
        g2.draw(centroaLin); 
        g2.draw(centrobLin);
        g2.draw(centrocLin);


        g.setColor(Color.RED);
        g2.draw(ladoH);

    } 

}



ADDITIONAL CODE TO FIND THE CIRCUMCENTER
A=((u-t)*z^2+(-u^2+t^2-q^2+p^2)*z+t*u^2+(-t^2+s^2-p^2)*u+(q^2-s^2)*t)/((q-p)*z+(p-s)*u+(s-q)*t)

B=-((q-p)*z^2+(p-s)*u^2+(s-q)*t^2+(q-p)*s^2+(p^2-  q^2)*s+p*q^2-p^2*q)/((q-p)*z+(p-s)*u+(s-q)*t)

C=-((p*u-q*t)*z^2+(-p*u^2+q*t^2-p*q^2+p^2*q)*z+s*t*u^2+(-s*t^2+p*s^2-p^2*s)*u+(q^2*s-q*s^2)*t)/((q-p)*z+(p-s)*u+(s-q)*t)
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT