Thread: area function using xy

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    8

    area function using xy

    I dont even have a clue, any tips how to begin?????

    I need to find an area of a triangle.

    User inputs x and y for Side A, B, C.

    I know how to do with just sides AB and C but how do I do it with xy for each point ABC.

    Lost

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    52
    create a function that uses the distance formula
    distance = sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-f1)))

    I think this is correct.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    13
    a = b * h / 2

    /|\
    / | \
    B / | \ C
    / |h \
    / | \
    ‾‾‾‾‾‾‾‾‾‾
    A(b)

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    13
    ah, crap

    a = b * h / 2

    ********** /|\
    ********* /* | \
    *******B /**| *\ C
    ********/** |h* \
    *******/*** |*** \
    *******‾‾‾‾‾‾‾‾‾‾
    **********A(b)

    (sorry, its messy, i know)

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    The height will be the difference of the 2 most extreme y coordinates, and the base will be the difference of the 2 most extreme x coordinates.

  6. #6
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    area = (base/2) * height

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    8

    almost have it

    ok, i worked out the code. Had to go with govtcheese's formula.

    But everything works now except answer comes as something like a hexadecimal number.

    Area = 1.04635e+34, it should say 7. Any clues.????? it is a float.

  8. #8
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    That's not a hex number - that's a huge number.

    Show your code - you must have done something wrong.

  9. #9
    Registered User
    Join Date
    Mar 2002
    Posts
    8

    here is code

    here is function code

    float area(Point& A, Point& B, Point& C)
    {
    int x2 = B.GetX() - A.GetX();
    int x3 = C.GetX() - A.GetX();
    int y3 = C.GetX() - A.GetX();
    int y2 = B.GetX() - A.GetX();

    return sqrt((x2*3) - (y3*y2)/2.0);

    }

    Does this help??

  10. #10
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > Does this help??

    Not at all....

    What's "Point"?

    Where the hell did that formula come from?

    Why are you only saying GetX?

  11. #11
    Registered User
    Join Date
    Mar 2002
    Posts
    8

    I just worked it out

    point comes from the class........sorry for wasting your time, but I worked it out. How embarrassing I forgot to include <cmath> for sqrt.

    anyway thanks for the area help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Post your games here...
    By Hammer in forum Game Programming
    Replies: 132
    Last Post: 02-28-2013, 09:29 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. Replies: 5
    Last Post: 02-08-2003, 07:42 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM