Output Equations in Java
I was wondering if anyone knew of a library that could take an equation like
x = (-b +- (b^2-4ac)^(1/2))/2
And turned it into something like:
Preferably I would not like the output to be an image, but an image output is fine. I just wanted to check if something like this exists before I start coding it myself.
Would this be a better placed question somewhere else?
first.I can't help you.But what do you want to achieve.That the parameters in this new Form will be valuable themselfs? If you know what i mean?
There are some packages in Java, that you can draw equations, graphs, shapes, etc.. Search on Google.
David J. Eck
I once generated html version 3.2. tags from an infix expression (there's a little thread about it in the AWT/Swing forum). First the infix expression was parsed to its abstract syntax tree; a visitor would visit all the nodes (where the nodes would tell the visitor their type of node) and html code was generated. It turned out a bit of a mess because html 3.2 isn't well suited to mark up mathematical expressions. Here's an example: the expression:
Originally Posted by jlbird
is compiled to an AST; the postfix form of the AST is:
((-b + sqrt(b**2-4*a*c))/2*a)
(note: +- is the token for the unary minus operator) and the html output is:
b +- b 2 ** 4 a * c * - sqrt + 2 / a *
As I wrote: html isn't the best output for mathematical infix expressions. If you can, select another output form. Parsing the infix expression is just standard technology (my version is a recursive descent parser).
(-<i>b</i>+<font color="#cc"><b>√</b></font>(<i>b</i><sup><font color="#8000">2</font></sup>−<font color="#8000">4</font>·
<i>a</i>·<i>c</i>)) ⁄ <font color="#8000">2</font>·<i>a</i>
You could try LaTex, if you can find a plugin viewer for Java that is.