简体   繁体   English

Java-Swing-Graphics2D-如何可视化数学函数

[英]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? 我刚刚遇到了一个有趣的事情,如数学函数,但据我所知,数学可能包含浮点函数值,但是Graphics2D只能用于绘制N个值,因为像素坐标不能像0.897一样,而是1或2等:(所以我只是想问一下如何绘制一些简单的数学图表,例如Java?

y=x y = x

or 要么

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

or 要么

y=x+5 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)? 是的,这很有趣,但是它只是用标记绘制图表,否则如何使用该函数在其上每N个像素绘制其他对象(例如,不是标记而是使用标记坐标放置JLabel)? 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(f(x))其中g将十进制返回值转换为像素。

g(x) can be something as simple as: take the input and multiply it by y=100 supposing your viewing window is 100x100. g(x)可以很简单:假设您的观察窗口为100x100,则将输入乘以y = 100。 I hope this makes sense...you'll also want to consider which portion of the 2D graph you're viewing. 我希望这是有道理的...您还需要考虑正在查看的2D图形的哪一部分。 Are you viewing all 4 quadrants? 您是否正在查看所有四个象限? If so g(x) will need to translate the values too considering that the viewing window has changed... 如果是这样,考虑到查看窗口已更改,g(x)也将需要转换值...

I hope this makes sense! 我希望这是有道理的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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