C + + implementation--to find the area of the triangle (Helen Formula) __c++

Source: Internet
Author: User

To find the area of the triangle
/* Syntax: result = AREA3 (float x1, float y1, float x2, float y2, float x3, float y3);
Parameters:
x1~3: Triangle 3 vertices x coordinate
y1~3: Triangle 3 vertex y-coordinate
return value: Triangle area///
*
method: Helen-Qin Jiu formula known triangle A,b,c, then S area =√[p (P- A) (P-b) (P-C)] (Helen Formula) (
of which p= (A+B+C)/2)/
float area3 (float x1, float y1, float x2, float y2, float x3, flo At y3) {

    float A, B, C, p, s;
    To find the three-side length
    a = sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));
    b = sqrt ((x1-x3) * (X1-X3) + (y1-y3) * (Y1-y3));
    c = sqrt ((x2-x3) * (X2-X3) + (y2-y3) * (Y2-y3));

    p = (A + B + c)/2;
    Find the area
    s = sqrt (p* (p-a) * (p-b) * (p-c));

    return s;

}
Test function
int main () {
    float x1, y1, x2, y2, X3, y3;
    while (cin>>x1>>y1>>x2>>y2>>x3>>y3) {
        cout << area3 (x1, y1, x2, y2, x3, y3);
    }
    return 0;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.