Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7188283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:02:42+00:00 2026-05-28T19:02:42+00:00

I seem to be having a bit of a math fail here… I need

  • 0

I seem to be having a bit of a math fail here… I need to convert an (x,y) point from one coordinate space to another – not in the sense of polar to cartesian or anything of the sort… just from one bound to another. i.e., for a particular (x,y) that falls in the rectangle with lower left (-100, -100) and upper right (100,100), I need to find out where that point would be in a rectangle with lower left (0,0) and upper right (500, 500).

I feel like this is just simple math but I’m having a heck of a time getting it right…

It is for a little computer graphics program written in java. Essentially there is a clip window that changes, and that clip window needs to fill the whole view window. Initial values for clip and view are given by the above rectangles, in that order. However, the clip could change to, for example, a rectangle with lower left (-80, -65) and upper right (75, 65). I would then need to convert a point that falls within that rectangle to a point that falls within the view window (lower left (0,0), upper right (500, 500))

Here is what I have for it right now:

public int normalizeX(float x) {
    float clipWidth = clipRight - clipLeft;
    int viewWidth = viewRight - viewLeft;
    x += 100; //Get x into range [0, 200] instead of [-100, 100]
    //First convert x to value within clip width, then "scale" to viewport width
    return (int)(((clipWidth*x)/200) * (viewWidth/clipWidth));
}

public int normalizeY(float y) {
    float clipHeight = clipTop - clipBottom;
    int viewHeight = viewTop - viewBottom;
    y += 100; //Get y into range [0, 200] instead of [-100, 100]
    //First convert y to value within clip height, then "scale" to viewport height
    return (int)(((clipHeight*y)/200) * (viewHeight/clipHeight));
}

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:02:43+00:00Added an answer on May 28, 2026 at 7:02 pm

    Assuming your old bounds are xLoOld and xHiOld (-80 and 75, respectively, in your example) and your new bounds are xLoNew and xHiNew (0 and 500, respectively, in your example), then you can normalize your xOld to your new coordinate system like this:

    xNew = (xOld-xLoOld) / (xHiOld-xLoOld) * (xHiNew-xLoNew) + xLoNew
    

    Same thing for y.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of a problem with moving specific data from one server
im having a bit troubled here. I cannot seem to understand what's the problem
I seem to be having a bit of trouble with using classes from other
Having a bit of a problem here on a matrix multiplication code. I seem
I am having a bit of trouble. It does not seem to be a
I'm having a bit of trouble getting a class to import. Here is my
Alright, so I'm having a bit of an issue here. Here is the loop.
Okay, so I seem to be having a bit of difficulty in adding ShareKit
Coming from Win32, I am having bit of an issue or a problem trying
I seem to be having a bit of an issue storing an SVG path

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.