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

  • Home
  • SEARCH
  • 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 779179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:53:14+00:00 2026-05-14T19:53:14+00:00

I have a problem due to my terrible math abilities, that I cannot figure

  • 0

I have a problem due to my terrible math abilities, that I cannot figure out how to scale a graph based on the maximum and minimum values so that the whole graph will fit onto the graph-area (400×420) without parts of it being off the screen (based on a given equation by user).

Let’s say I have this code, and it automatically draws squares and then the line graph based on these values. What is the formula (what do I multiply) to scale it so that it fits into the small graphing area?

vector<int> m_x;
vector<int> m_y; // gets automatically filled by user equation or values

int HeightInPixels = 420;// Graphing area size!!
int WidthInPixels = 400;
int best_max_y = GetMaxOfVector(m_y);
int best_min_y = GetMinOfVector(m_y);
m_row = 0;
m_col = 0;

y_magnitude = (HeightInPixels/(best_max_y+best_min_y)); // probably won't work
x_magnitude = (WidthInPixels/(int)m_x.size());
m_col = m_row = best_max_y; // number of vertical/horizontal lines to draw

////x_magnitude = (WidthInPixels/(int)m_x.size())/2; Doesn't work well
////y_magnitude = (HeightInPixels/(int)m_y.size())/2; Doesn't work well

ready = true; // we have values, graph it
Invalidate(); // uses WM_PAINT

////////////////////////////////////////////
/// Construction of Graph layout on WM_PAINT, before painting line graph
///////////////////////////////////////////
CPen pSilver(PS_SOLID, 1, RGB(150, 150, 150) ); // silver
    CPen pDarkSilver(PS_SOLID, 2, RGB(120, 120, 120) ); // dark silver
    dc.SelectObject( pSilver ); // silver color
    CPoint pt( 620, 620 ); // origin
    int left_side = 310;
    int top_side = 30;
    int bottom_side = 450;
    int right_side = 710; // create a rectangle border
    dc.Rectangle(left_side,top_side,right_side,bottom_side);
    int origin = 310;
    int xshift = 30;
    int yshift = 30;
    // draw scaled rows and columns
    for(int r = 1; r <= colrow; r++){ // draw rows
        pt.x = left_side;
        pt.y = (ymagnitude)*r+top_side;
        dc.MoveTo( pt );
        pt.x = right_side;
        dc.LineTo( pt );
        for(int c = 1; c <= colrow; c++){
            pt.x = left_side+c*(magnitude);
            pt.y = top_side;
            dc.MoveTo(pt);
            pt.y = bottom_side;
            dc.LineTo(pt);
        } // draw columns
    }
    // grab the center of the graph on x and y dimension
    int top_center = ((right_side-left_side)/2)+left_side;
    int bottom_center = ((bottom_side-top_side)/2)+top_side;
  • 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-14T19:53:14+00:00Added an answer on May 14, 2026 at 7:53 pm

    You are using ax^2 + bx + c (quadratic equation). You will get list of (X,Y) values inserted by user.
    Let us say 5 points you get are

    (1,1)
    (2,4)
    (4,1)
    (5,6)
    (6,7)

    So, here your best_max_y will be 7 and best_min_y will be 1.
    Now you have total graph area is

    Dx = right_side - left_side //here, 400 (710 - 310)
    Dy = bottom_side - top_side //here, 420 (450 - 30)

    So, you can calculate x_magnitude and y_magnitude using following equation :


    x_magnitude = WidthInPixels / Dx;
    y_magnitude = HeightInPixels / Dy;

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

Sidebar

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.