Results 1 to 10 of 10

Thread: [RESOLVED] how calculate the center of a rectangule?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Resolved [RESOLVED] how calculate the center of a rectangule?

    i have one rectangule with these size(for example): 10X20(W,H)
    how can i calculate the center (X,Y) of the rectangule?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: how calculate the center of a rectangule?

    That depends on which coordinate system you have chosen.

    If your rectangle has it's lower-left corner in the origin (0,0) then the center is at (x,y) = (5, 10), because x is half the width, and y is half the height.

    You could also choose your rectangle to lie with its center in the origin. Then ofcourse the center would be at (0,0).

    You could also rotate your rectangle and put it somewhere random, then you would need to draw me a diagram with appropriate angles and distances and I can show you how to work it out.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: how calculate the center of a rectangule?

    my objective is transform the rectangle image in math circule cartegian(i'm sorry but i don't know the english right term)
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: how calculate the center of a rectangule?

    You want to transform a rectangle into a circle? How do you intend on doing that lol. Sorry I don't know what you mean.

    Do you perhaps want to find a circle that lies inside the rectangle (touching the sides)?

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: how calculate the center of a rectangule?

    Quote Originally Posted by NickThissen
    You want to transform a rectangle into a circle? How do you intend on doing that lol. Sorry I don't know what you mean.

    Do you perhaps want to find a circle that lies inside the rectangle (touching the sides)?
    lool you have right... what i'm trying to say is that i'm transform the rectangule coordenates that are both positive(X,Y) to the cartegian "circule".
    has we know the retangule start with (0,0) to something, but the cartegian is a little diferent. work with negative values, have 4 quadrants.

    heres the image:
    the rectangule is in middle of cartegian(is the 1st objective), but has we know the rectangule points start in (0,0) and the Y for down is positive not negative(like the cartegian). perhaps my error is here, i don't know. but i can see the image(not in right rotation) and not complete image. i can see some space between the pixels.
    thanks
    Attached Images Attached Images  
    Last edited by joaquim; Jun 21st, 2008 at 01:32 AM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: how calculate the center of a rectangule?

    Are you trying to convert between polar and rectangular? If not, more pictures overcome language barriers
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: how calculate the center of a rectangule?

    Quote Originally Posted by jemidiah
    Are you trying to convert between polar and rectangular? If not, more pictures overcome language barriers
    i'm sorry but i don't hunderstand. the center of rectangule must be (0,0) in cartegiano
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how calculate the center of a rectangule?

    Quote Originally Posted by joaquim
    l
    the rectangule is in middle of cartegian(is the 1st objective), but has we know the rectangule points start in (0,0) and the Y for down is positive not negative(like the cartegian). perhaps my error is here, i don't know. but i can see the image(not in right rotation) and not complete image. i can see some space between the pixels.
    thanks
    Are you referring to the way Pixel-coordinates are given (Y=0 at the top going down increases the value, X=0 at the left going right increases the value). This is of course different to the cartesian way to count. However that wouldn't change the calculation of your centre of rectangular object!!
    If you cant see the image, I assume you try to show it using code. In order to show this rectangular at the "correct" position and "correct" rotation you need to convert the coordinates!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  9. #9
    New Member
    Join Date
    Jul 2008
    Posts
    10

    Re: how calculate the center of a rectangule?

    If the co-ordinates of the 4 corners are (x1,y1), (x2,y2), (x3,y3), (x4,y4) then the co-ordinates of the centre are (xc,yc) where xc= (x1+x2+x3+x4)/4 and yc= (y1+y2+y3+y4)/4 and this is the case irrespective of the origin of the co-ordinates.

    You can see this by considering the mid-points of (any) two opposite sides these are for example: ((x1+x2)/2, (y1+y2)/2) and ((x3+x4)/2, (y3+y4)/2). The centre is then the mid-point of these two points.

    Rob
    Last edited by EvoRob; Jul 18th, 2008 at 03:07 AM.

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,959

    Re: how calculate the center of a rectangule?

    thanks to everyone, i found the solution....
    heres my objective
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width