Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Graphing calculator problem (VB.NET)

Graphing calculator problem (VB.NET)

Scheduled Pinned Locked Moved Visual Basic
csharpalgorithmsdata-structureshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jacobjordan
    wrote on last edited by
    #1

    Ok, well i am making a graphing calculator, and it's the simplest part i can't seem to figure out. I have a panel that is 416x416, which the graph will be drawn on. I have variables, xMin, xMax, yMin, yMax, that store the minimum and maximum for the x and y values. Now, the first step in rendering the graph is to draw the X and Y axises, and based on the minimum and maximum of the values will determine where the origin for the graph is. That's what i'm having problem with, i can't seem to generate code that will, in pixels, give the origin for the graph. Right now, the calculator only works if -xMin = xMax = -yMin = yMax, meaning the origin would be in the center of the 416x416 panel, at point (208, 208). If the xMax was twice as much as the -xMin, then the X axis would be 1/4 off of the panels left side. I can't seem to code an algorithm, when passed the xMax, xMin, ect., will return the origin of the graph. It will work with some values, but not all. Please let me know if i have not explained enough.

    void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

    T 1 Reply Last reply
    0
    • J jacobjordan

      Ok, well i am making a graphing calculator, and it's the simplest part i can't seem to figure out. I have a panel that is 416x416, which the graph will be drawn on. I have variables, xMin, xMax, yMin, yMax, that store the minimum and maximum for the x and y values. Now, the first step in rendering the graph is to draw the X and Y axises, and based on the minimum and maximum of the values will determine where the origin for the graph is. That's what i'm having problem with, i can't seem to generate code that will, in pixels, give the origin for the graph. Right now, the calculator only works if -xMin = xMax = -yMin = yMax, meaning the origin would be in the center of the 416x416 panel, at point (208, 208). If the xMax was twice as much as the -xMin, then the X axis would be 1/4 off of the panels left side. I can't seem to code an algorithm, when passed the xMax, xMin, ect., will return the origin of the graph. It will work with some values, but not all. Please let me know if i have not explained enough.

      void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

      T Offline
      T Offline
      The Cadde
      wrote on last edited by
      #2

      have you tried (math.abs(xMin) + xMax) / 2 That is if xMin is "-200" and xMax is 400 the result is (200 + 400) / 2 = 300 EDIT: Unless you are already using negative values in X, Y then you would use ((math.abs(xMin) + xMax) / 2) - math.abs(xMin) or ((200 + 400) / 2) - 200 = 100

      J 1 Reply Last reply
      0
      • T The Cadde

        have you tried (math.abs(xMin) + xMax) / 2 That is if xMin is "-200" and xMax is 400 the result is (200 + 400) / 2 = 300 EDIT: Unless you are already using negative values in X, Y then you would use ((math.abs(xMin) + xMax) / 2) - math.abs(xMin) or ((200 + 400) / 2) - 200 = 100

        J Offline
        J Offline
        jacobjordan
        wrote on last edited by
        #3

        A million thanks. I had tried something like that, but it was so complicated and didn't even work. Can't believe it was that simple.

        void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups