Thread: structures

  1. #16
    Registered User sballew's Avatar
    Join Date
    Sep 2001
    Posts
    157
    nevermind, I figured it out.
    Sue B.

    dazed and confused


  2. #17
    Registered User sballew's Avatar
    Join Date
    Sep 2001
    Posts
    157

    FINDING R's CENTER POINT

    How would I now code a function
    to find rectangle r's center point;
    returning point as my result????


    one thing I know, is that I will have to type cast the result
    because could have possible answer like (2.5, 4.5) etc.



    I also I know center coordinates are based on following:

    (rect.lower_right.x - rect.lower_right.y)/2 = x coordinate of center
    (rect.upper_left.y - rect.upper_left.x)/2 = y-coordinate of center



    Now how to incorporate all this into a function definition,
    I don't know.


    Any further help, would be wonderful.
    Sue B.

    dazed and confused


  3. #18
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    The best way to do this is to add to double types to your structure. They are part of the rectangle logic. So put these in the structure declaration and use them.

    double cx; //center x co-ordinate
    double cy; //center y co-ordinate

  4. #19
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Better yet:

    double center[2];

  5. #20
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    ^
    | UL
    | _ _ _ _ _
    | | |
    | |_ _ _ _ _|
    | LR
    |
    | |
    ______________________________
    for rectangles like above
    rect.upper_left.y > rect.lower_right.y
    so you get the negative of the actual area

    int area_of_r ( struct rectangle rect ) {
    int area;
    area = (rect.lower_right.x - rect.upper_left.x ) *
    ( rect.upper_left.y - rect.lower_right.y);
    /*(rect.lower_right.y - rect.upper_left.y );*/

    return area;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM