三角形面积计算

已知三条边和外接圆半径,公式为s = a*b*c/(4*R)

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        double a=sc.nextDouble();
        double b=sc.nextDouble();
        double c=sc.nextDouble();
        double R=sc.nextDouble();
        System.out.println(GetArea(a,b,c,R));

    }

    private static double GetArea(double a, double b, double c,double R) {
        return a*b*c/4/R;
    }
}

已知三条边和内接圆半径,公式为p=(a+b+c)/2  ;  s = pr

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        double a=sc.nextDouble();
        double b=sc.nextDouble();
        double c=sc.nextDouble();
        double r=sc.nextDouble();
        System.out.println(GetArea(a,b,c,r));

    }

    private static double GetArea(double a, double b, double c,double r) {
        return r*(a+b+c)/2;
    }
}

已知三角形三条边,求面积

先判断输入的三边数值是否可以构成三角形(两边之和大于第三边)

求三角形面积公式为:p=(a+b+c)/2;

                                s=Math.sqrt(p*(p-a)*(p-b)*(p-c))

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        double a=sc.nextDouble();
        double b=sc.nextDouble();
        double c=sc.nextDouble();
        GetArea(a,b,c);
    }
    public static void GetArea(double a, double b, double c){
        if(a+b>c && b+c>a && a+c>b){
            double p = (a+b+c)/2;
            double s =Math.sqrt(p*(p-a)*(p-b)*(p-c));
            System.out.println(s);
        }else{
            System.out.println("你输入的不是三角形");
        }
    }
}

已知三角形三个顶点的坐标

S = abs(x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2))/2;

import java.awt.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        double x1,x2,x3,y1,y2,y3;
        Point p1=new Point();
        Point p2=new Point();
        Point p3=new Point();
        x1=sc.nextDouble();
        y1=sc.nextDouble();
        x2=sc.nextDouble();
        y2=sc.nextDouble();
        x3=sc.nextDouble();
        y3=sc.nextDouble();
        p1.setLocation(x1, y1);
        p2.setLocation(x2, y2);
        p3.setLocation(x3, y3);
        double s1=p1.distance(p1);
        double s2=p2.distance(p2);
        double s3=p3.distance(p3);
        System.out.println(GetArea04(p1,p2,p3));

    }
    //已知三角形三个顶点的坐标
    private static double GetArea04(Point p1, Point p2, Point p3) {
        double t =-p2.x*p1.y+p3.x*p1.y+p1.x*p2.y-p3.x*p2.y-p1.x*p3.y+p2.x*p3.y;
        if(t<0) t = -t;
        return t/2;
    }
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值