Jump to content
IGNORED

Graphing calculator program, how to draw line between points


Recommended Posts

I'm currently writing programs to use the Atari 8-bit emulator like a crude graphing calculator. While I figured out how to make graphs appear on the screen, I have some trouble with connecting the plotted points together to get a better sense of what I'm looking at. Drawto seems to be the correct command to use, but it doesn't always work out on every function I plot out; sometimes it works, and other times it causes a numerical overflow error trying to plot a number too big for the limited screen dimensions. Is there a trick to getting the points connected together that isn't super dependent on the function I define?

Link to comment
Share on other sites

Your request is kind of funny, getting points connected together not depending on function you define. Sounds like random points connected with lines :)

 

Ok, now the solution... I anticipate you are doing this in basic. You simply have to clip your coordinates to the size of screen. Easiest fix would be to check if coordinates of next point are positive numbers, and if so whether x coord. Is lower than 320 and y coord. lower than 192....(assuming gr.8) So if all these conditions applies then call drawto. If not, skip the point. Also very next valid point should be drawn with Plot and all the next valid ones with drawto again.

 

Other fix, nicer but more complicated would be to calculate intersection between your line and screen bounds, by using simple goniometric calculations. I suppose if you are working on some graph calculator, you know how to calculate it since it is elementary school stuff. Don't forget to use DEG to switch to degrees. Then it is basically ATN of division of differences between x and y coordinates, that's the way to get the angle of the line to be drawn. Next step is to use the angle to calculate point of screen intersection using SIN and COS.

It may require multiple variants depending on which screen bound the line crosses.

  • Like 1
Link to comment
Share on other sites

Clipping coordinates likely won't be helpful as the gradient of the line would then be wrong (assuming line graph with connected points)

 

The OS actually allows some overdraw in a destination for the DRAWTO then just spits up ERROR 141 once a coordinate is out of range so at least there you'll have the proper gradient.

Problem is, negative values aren't allowed and the positive values have their bounds constrained - Y values can't go beyond 255 though big X values seem to be permitted.

 

Probably the best you could do is constrain your graph so it stays onscreen.  e.g. Calculate what the bar heights will be then scale them back.   Similar deal if it's connected points in a line graph.

Edited by Rybags
Link to comment
Share on other sites

On 11/7/2021 at 8:45 AM, Irgendwer said:

Maybe the attached program does already what you like?

If not, browsing through the Turbo-Basic source code could be helpful...

 

grafik.thumb.png.23409ddf997de06768f5b399e203520a.png

Analysis.atr 90.02 kB · 6 downloads

I was kinda hoping I could code my own, but I guess this'll do. I don't suppose there's an English translation? I'm not fluent in German.

Link to comment
Share on other sites

15 hours ago, mr. engino said:

I was kinda hoping I could code my own, but I guess this'll do. I don't suppose there's an English translation? I'm not fluent in German.

No English translation yet, but if you like to create one... ...most strings should go easily through Google translate and you could release a patched version?

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...