根据三个点的坐标计算三角形面积
生活随笔
收集整理的這篇文章主要介紹了
根据三个点的坐标计算三角形面积
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
package chaper2;import java.sql.SQLOutput;
import java.util.Scanner;/*** 編寫程序,提示用戶輸人三角形的三個(gè)點(diǎn)(x1,y1)、(x2,y2) 和 (x3,y3), 然后顯示它的面積。計(jì)算三角形面積的公式是:** s=(邊1+邊2+邊3)/2** 面積: (s * (s - 邊1)(s - 邊2)(s - 邊3))^0.5* @author siyihe* @create 2022-06-23 17:15* @project javaexec0*/
public class Triangle {public static void main(String[] args) {Scanner input =new Scanner(System.in);System.out.println("Enter the coordinates of three points separated by spaces \n like x1 x2 x3 y1 y2 y3: ");double x1=input.nextDouble();double y1=input.nextDouble();double x2=input.nextDouble();double y2=input.nextDouble();double x3=input.nextDouble();double y3=input.nextDouble();double s1=Math.pow((Math.pow((x2-x1),2)+Math.pow((y2-y1),2)),0.5);double s2=Math.pow((Math.pow((x3-x2),2)+Math.pow((y3-y2),2)),0.5);double s3=Math.pow((Math.pow((x1-x3),2)+Math.pow((y1-y3),2)),0.5);double s=(s1+s2+s3)/2;double area=Math.pow(s*(s-s1)*(s-s2)*(s-s3),0.5);System.out.println("The area of the triangle is "+area);}}
總結(jié)
以上是生活随笔為你收集整理的根据三个点的坐标计算三角形面积的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【前端】纯CSS实现探照灯效果
- 下一篇: 聊一聊搭建一个网站到底有几步?