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 9195225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:34:59+00:00 2026-06-17T21:34:59+00:00

I don’t know how to formulate what the algorithm I need does in fewer

  • 0

I don’t know how to formulate what the algorithm I need does in fewer words; it is highly possible that such question is already answered here, but I don’t know how to search for it.

What I need is the following.
I’m writing kind of 2D graph plotting program. Obviously, drawing only main coordinate lines is not very good, since the graph can be located far from the origin, and the user will not have any reference for its size if only main lines are drawn.
I decided to draw reference lines, that is, horizontal and vertical lines which appear periodically with constant interval, corresponding to e.g. whole numbers. However, using constant intervals does not work so great because of possibility of scaling, that is, if user zooms in to see, for example, internals of unit square, he will again see nearly empty box without any reference to sizes.

So, I need to somehow rescale the interval which I use to draw the reference lines. In other words, I need a function of type like double -> double which accepts current scale coefficient (the one I use specifies how many pixels are in one unit of length) or a value of some function applied to it (e.g. maximum number of unit lengths which can fit inside the screen along some axis) and returns a value of step (in pixels on in logical units, does not matter), that is, the length of the interval between reference lines.

I believe that the set of values of such function would be countably infinite, that is, this function would map intervals of scale coefficient value to fixed values of the step. I can give rough description of the algorithm, or, more correctly, the mapping I need. It looks similarly to this (input value is the maximum number of units inside the screen):

  • …
  • [5..9] -> 0.25
  • [9..15] -> 0.5
  • [15..30] -> 1
  • …

The values here are purely empirical and used only for illustration.

However, I don’t know how to extrapolate this set of mappings to wider range of scale coefficient values, let alone how to express such dependency analytically. Yet I’m sure that this is possible because I saw such thing in many graphing programs.

I found this question which looks very close to what I need, but I couldn’t manage to adapt the answer to it to my task since it mentions label width and I don’t have any labels.

  • 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-06-17T21:35:00+00:00Added an answer on June 17, 2026 at 9:35 pm

    You can define it precisely for one order of magnitude (power of ten) and then treat other orders of magnitude similarly and convert back, e.g.

    double tickStep(double pixelDistance)
    {
         if(pixelDistance <= 3.0)
           return(tickStep(pixelDistance * 10.0) / 10.0);
         else if(pixelDistance > 3.0 && pixelDistance <= 5.0)
            return(0.125);
         else if(pixelDistance > 5.0 && pixelDistance <= 9.0)
            return(0.25);
         else if(pixelDistance > 9.0 && pixelDistance <= 15.0)
            return(0.5);
         else if(pixelDistance > 15.0 && pixelDistance <= 30.0)
            return(1.0);
         else if(pixelDistance > 30.0)
            return(tickStep(pixelDistance / 10.0) * 10.0);
    }
    

    I’ve used recursion to clarify the idea, but it’s probably more efficient to use log and pow.

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

Sidebar

Related Questions

Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to google for such, but is there a way to query
Don't know if you got my question, so here is an example. I have
Don't know a whole lot about streams. Why does the first version work using
Don't worry, I'm not going to ask that question, yet again... I am wanting
Don't know is it possible to copy elements from one map to another map
Don't know if this is possible, but I have some code like this: val
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't know the term for the red validation border, does it have one? I
Don't know if there is a better way to do this, so that is

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.