Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Master extends Triangle{
- Master(){}
- public void master(Triangle t1 , Triangle t2) {
- for(int i = 0 ; i < 3 ; i++) {
- if(t1.xPoly[i] == t2.xPoly[i] && t1.yPoly[i] == t2.yPoly[i]) {
- int n = ++i;
- System.out.println("точка "+ n + " є спільною для 2 трикутників");
- }
- }
- }}
- import java.awt.*;
- import java.lang.*;
- public class Triangle {
- protected int xPoly[] = new int [3];
- protected int yPoly[] = new int [3];
- public int length = 3;
- public Triangle() {
- xPoly[0] = 70;
- yPoly[0] = 100;
- xPoly[1] = 150;
- yPoly[1] = 200;
- xPoly[2] = 200;
- yPoly[2] = 100;
- }
- public Triangle(int xPoly[], int yPoly[]){
- this.xPoly = xPoly;
- this.yPoly = yPoly;
- }
- public void getRadius() {
- double a = Math.sqrt(Math.pow(xPoly[1] - xPoly[0],2) + Math.pow(yPoly[1] - yPoly[0], 2));
- double b = Math.sqrt(Math.pow(xPoly[2] - xPoly[1],2) + Math.pow(yPoly[2] - yPoly[1], 2));
- double c = Math.sqrt(Math.pow(xPoly[0] - xPoly[2],2) + Math.pow(yPoly[0] - yPoly[2], 2));
- double p = (a + b + c) / 2;
- double S = Math.sqrt(p* (p-a) * (p-b) * (p - c));
- double R = (a* b* c) / (4 *S);
- System.out.println(R);
- }
- public void Visible () {
- Boolean per = true ;
- for(int i = 0 ; i < 3 ; i++) {
- if(xPoly[i] < 0 || xPoly[i] > 250 || yPoly[i] < 0 || yPoly[i] > 250 )
- per = false;
- }
- if(per == true)
- { System.out.println("All points is inside the frame");}
- else
- { System.out.println("At least one point is outside the frame");}
- }
- public void drawTriangle(Graphics g) {
- g.drawPolygon(new Polygon(xPoly, yPoly, xPoly.length));
- }
- }
- import java.awt.*;
- import java.awt.event.*;
- public class DvaClass extends Frame{
- private int Nabi[] = { 70, 100 , 140};
- private int Genuk[] = { 100, 130 , 130};
- Triangle ob1 = new Triangle();
- Triangle ob2 = new Triangle(Nabi , Genuk);
- Master m1 = new Master();
- Stroke drawingStroke = new BasicStroke(2);
- public void paint(Graphics g) {
- Graphics2D graph = (Graphics2D)g;
- ob1.drawTriangle(graph);
- ob2.drawTriangle(graph);
- ob1.getRadius();
- ob2.getRadius();
- ob1.Visible();
- ob2.Visible();
- m1.master(ob1, ob2);
- }
- public static void main(String args[]) {
- Frame frame = new DvaClass();
- frame.addWindowListener(
- new WindowAdapter(){
- public void windowClosing(WindowEvent we){
- System.exit(0);
- }
- }
- );
- frame.setSize(250, 250);
- frame.setVisible(true);
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement