locked
Storing and Displaying Equations RRS feed

  • Question

  • Hi all,

    I am currently developing an App for storing engineering formulae. The formulas are actually somewhat complex, I am not talking about something like x^2 + x + 2 = 0. A good example could be the torque for an asynchronous 3-phase electric motor, like this one:

     

    So far, I have 2 questions related to these formulae:

    1. I need a way to store them in SQL database (or somewhere else) so I can call them when needed in code. I learned from the community that SVG may not be the way to do it. In that case, which is the best, standardized way to achieve this? I am currently writing each formula using LaTeX equation editor, then saving them as SVG, by using:

    http://www.codecogs.com/latex/eqneditor.php

    as recommended in the forums.

    2. Once the formula is in SQL, I also need a way to show it inside a WP8 App. By showing it, I mean I do not wish to show an image, namely a JPG caption. I actually want the user to see what can be seen inside apps such like this one:

    http://www.windowsphone.com/en-us/store/app/function-plotter/491f6fea-f79c-e011-986b-78e7d1fa76f8

    that actually shows the equations in a nicely, standard UI manner according to Microsoft. But the formulas within that App are rather simple, not needed of big math structures.

    So, the question so far would be: How can I get to show complex formulae in a clean, nice way?

    Thanks in advance.

    PepeChan

    Tuesday, January 7, 2014 2:48 PM

Answers

  • You can either render SVG inside WebControl or you can convert SVG to XAML. Either way, you have to keep it in the original format since it is a vector image.

    As for binding, you don't do it that way. You cannot bind to assets, you can bind to in memory object. But you can load assets dynamically. Do you have a lot of experience with writing Windows Phone applications?


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    • Marked as answer by Pepe Vera Wednesday, January 8, 2014 10:29 AM
    Wednesday, January 8, 2014 10:02 AM

All replies

  • Have you tried using a SVG to XAML converter?

    http://pauliom.wordpress.com

    Tuesday, January 7, 2014 2:56 PM
  • Hi pkr2000,

    nope, but I will give it a try since it would probably keep me from storing all data in SQL. For storing purposes, keeping a DB should be not necessary at all for only taking care of some formulae.

     On the other hand, they will be a lot in the end, some 2000 or so, which is why I was a little afraid of not having a DB instead. Do you know whether it is posible to store SVG or at least XML formulas in a database?

    Nevertheless, I guess I could be able to store data in the Assets folder despite becoming a little unmanageable in the end.

    Anyway, thanks a lot for the tip. I think there are some converters out there that work well within Blend.

    As far as I am concerned, SVG to XAML would imply that I have to recreate the formulae in XAML rather tan calling them from a class, is this right?


    PepeChan

    Wednesday, January 8, 2014 8:38 AM
  • 1. SVG is actually a simple text and you can save text normally in the database. However, displaying it is another thing.

    2. What you want to do there is called function plotting. You can do that easily by simply calculating a series of points and then drawing lines that connect those points. To display the geometry, use Canvas element. But beware, if you need to add zooming and panning capability, you will have to do it yourself.

    --

    I am not sure if you understand that SVG file you get from the linked site is actually a representation of the formula itself. This is because formulas have to look pretty and they can have lots of elements not representable in any standard text control. It is by no means usable for you in mathematical calculations.

    If you want to render graphs (plot functions) you need to have a different representation in your code for function evaluation. You need to be able to evaluate the function at different sampling points to get coordinates for drawing on the screen.




    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, January 8, 2014 9:05 AM
  • Thaks Toni, but I will not go that far.

    Actually, what I want to do is giving the user of an App a means to look for a specific formula and simply retrieve it on screen. Usually engineers need to recall a formula on the go and having an App for this should suffice.

    But I would like the user to see the formula in Windows Phone style, not seeing a simple image. I want the user to "read text" which happens to be a formula. Dealing with images and resolutions would be a pain and use a lot of space. In addition, some formulas are quite short while others are very large. Think of a large library of formulas to look for, sorted in a manner that an engineer can search for and use quickly.

    The user will not use the formula to calculate values (at least not now) nor plotting x,y values on screen or the like.

    The purpose of the App is only to be a handbook of formulas, but displayed as Windows phone text (aka, Segoe UI), while keeping the math format for each formula, not being a simple string.

    I will use an equation editor for writing every formula and then saving as either SVG, EMF or the like. I can use CorelDraw to save them as AI files and use them in Blend, as well. Then I would like to store them either in Assets folder or inside SQL DB. But I was thinking of the best way to store and retrieve each formula, as simple as that.

    For sure zooming, panning or plotting will not be features of the App. The main concern is how to manage the formula itself.


    PepeChan


    • Edited by Pepe Vera Wednesday, January 8, 2014 9:36 AM
    Wednesday, January 8, 2014 9:34 AM
  • I don't understand what your problem is than. You need to display a list of friendly names for formulas in one large listbox, maybe optionally providing a search function, and when a formula is tapped, you navigate to a special screen which shows the formula itself in SVG format, similar to the LaTeX version.

    You don't want to display formula in any other way since mathematical formulas should be represented in specific typefaces that are best for displaying formulas. Not to mention all the graphical adornments which don't exist in fonts and would be hard to recreate yourself.

    How you will store the formulas depends on multiple factors, but if you don't plan to update the list other than via application updates, you can add them as assets and then you can also add a special file that contains a list of all included formulas. DB is an overkill for such a simple scenario.


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, January 8, 2014 9:42 AM
  • Oh,

    I thought you cannot use SVG directly into a screen in a WP App project.

    So do you mean all I have to do is simply binding every item in XAML to an asset inside Assets folder and that´s all? Will it work for SVG graphics? Then it could be a really simple solution, since even CorelDraw can save a file as SVG directly, of course using Segoe UI as with any other Font...

    Ok, I will give it a try then.

    Thanks for the tip Toni.


    PepeChan

    Wednesday, January 8, 2014 9:51 AM
  • You can either render SVG inside WebControl or you can convert SVG to XAML. Either way, you have to keep it in the original format since it is a vector image.

    As for binding, you don't do it that way. You cannot bind to assets, you can bind to in memory object. But you can load assets dynamically. Do you have a lot of experience with writing Windows Phone applications?


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    • Marked as answer by Pepe Vera Wednesday, January 8, 2014 10:29 AM
    Wednesday, January 8, 2014 10:02 AM
  • Nope, only with C# actually.

    I can also understand MVVM pattern, although not very proficiently. I have not used it for a real project yet.

    Also pkr2000 suggested me to look for SVG to XAML converters, I am looking for them as well.

    I work as mechanical engineer on a daily basis, and some of my fellows and me were thinking about having an App for those times when we need to recall a formula and have no references at hand.

    All code I write, I do because I like it and by no means I am a professional developer.

    When I was stating "binding to an asset" I was referring to linking to what is inside public void LoadData() method inside my model. Sorry for my naming convention, I guess this is usual with not seasoned developers... :)


    PepeChan

    Wednesday, January 8, 2014 10:15 AM
  • No problem, just wanted to make sure that you understand what you want. If you need some further help or a starting app template, I can help you with that.

    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, January 8, 2014 10:30 AM
  • Thank you Toni.

    Actually, I was planning to use the Pivot App template since the formulas are stored in categories and subcategories, namely:

    1. Physics

       1.1. Kinematics

       1.2. Dynamics

    2. Flow

    3. Thermal... and the like.

    Then, say the user navigates to Physics, then click on Dynamics. I should then include a second level of navigation since Dynamics is not the final path, but stores several Dynamics-related formulae instead.

    The user then tries the one single formula in the list that he or she thinks is the right one. The final destination would be then a page that displays the formula with maybe some explanation by scrolling down, with variables names, etc.

    In addition, there is the likelihood that a formula is better understood with a caption/image next to it. Then I was thinking of a Panorama-like or, again, Pivot-like way of showing the formula.

    In case the formula is a standalone piece of information, a single page should be enough. Otherwise, the user should be able to scroll left or right to see further information related to that specific formula. In the formula I used in my first asking post, for example, the user can see the formula, but to better understand the variables, he or she should scroll right to see a graph or diagram depicting the schema that led to the formula.

    I am still thinking on the best way to implement this navigation scheme. Do you have any suggestion or should I start another thread for this?


    PepeChan

    Wednesday, January 8, 2014 10:49 AM
  • We should move out of the forums perhaps. You can find me on twitter @to_pe or linkedin (check my profile) and I could give you tips and general help.


    Toni Petrina
    My blog: Toni codes .NET
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful"

    Wednesday, January 8, 2014 11:39 AM
  • Hi,

      My suggestion will be to maintain the formula to be displayed as a picture format which is easy to just display. For manipulation use a different format which is easy for you to apply the value and calculate. I have my own App "Math Formulas" which shows complex equations all are stored as images in SQlite


    Regards Senthamil

    Wednesday, January 8, 2014 12:47 PM