简体   繁体   中英

Java - swing - Graphics2D - how to visualize math functions

I've just faced an interesting thing as Math functions but as I can get it Math may contain float function values but Graphics2D can be used to paint just N values because pixels coordinates cannot be like 0.897 but 1 or 2 etc :( So I just want to ask how to paint some simple math charts like in Java?

y=x

or

y=x*tan(alpha)+3; abs(x)

or

y=x+5

etc

I have found this kind of code; 在此处输入图片说明

OK it is quite interesting but it just paints chart with markers but otherwise how the function can be used to paint some other object each N pixels right upon it (not marker but to place a JLabel with markers coordinates for example)? And how not to show the coordinates border ?

The return values of some math functions can be scaled to the graph's viewing window. Since you're a math person, I'll put it in more math-like terms: you need to create a mapping function that can be applied to the output of your math function...so g(f(x)) where g translates a decimal return value to a pixel.

g(x) can be something as simple as: take the input and multiply it by y=100 supposing your viewing window is 100x100. I hope this makes sense...you'll also want to consider which portion of the 2D graph you're viewing. Are you viewing all 4 quadrants? If so g(x) will need to translate the values too considering that the viewing window has changed...

I hope this makes sense!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM