Category Archives: Coding

Programming stuff

Common issues with circular coordinates

For a tube simulation I am doing I am working with circular coordinates. I.e. a point on the wall of the tube could be defined by two parameters: the point along the centerline (spline) of the tube, and the angular coordinate given in the range [0,1].

Because the angular coordinate 1 describes a full rotation, 1 = 0; (because 360 degrees will give the same result as 0 degrees rotation)

This leads to a couple of issues if we want to calculate the difference between two angular coordinates, or the mean between two angular coordinates.

Continue reading

Selecting GameObjects with a generic ComboBox in Unity3d

objectComboBox

Unity’s GUI System does not offer a Combo Box at the time of writing and I needed a ComboBox to select different objects of a certain MonoBehaviour type in my simulation. Based on the ComboBox from here (there are a number of variations) I came up with my quick’n’dirty ObjectComboBox.cs script. It is a generic class that takes any kind of UnityEngine.Object (or an extension of Object) as a type parameter. That means any MonoBehaviour, Transform, GameObject, Vector3, you name it.

Continue reading

Screenshot Coroutine Demo

Waiting for Simulation Results using Coroutines in Unity3d

In an algorithm that I am implementing for my thesis, I need to wait for information from the simulation before I can continue the algorithm. In a multi-threaded application you could just create multiple threads with chunks of work that have to wait until other work is finished. But without multithreading there is a problem: How do you wait for something without blocking the entire Application while still tracking the state of an algorithm? Continue reading

Replacing German Umlauts

I had to quickly write a method to replace german umlaute in filenames before saving them to disk (File upload in a JSF application)

Using the jave.text.Normalizer class or the regex match \\p{InCombiningDiacriticalMarks}+ wasn’t of a lot of help, because I couldn’t replace the umlaute in the correct form by appending an e (ö as oe etc.). Additionally there is an issue with capitalization. ÜBUNG should be all capitalized UEBUNG. While Übung should become Uebung and a single capital Ü will become Ue. An umlaut followed by a digit will be all capitalized “TÜ24″ => “TUE24″.

Based on this solution I wrote the following function, the results are almost the same:

   /**
     * Replaces all german umlaute in the input string with the usual replacement 
     * scheme, also taking into account capitilization.
     * A test String such as 
     * "Käse Köln Füße Öl Übel Äü Üß ÄÖÜ Ä Ö Ü ÜBUNG" will yield the result 
     * "Kaese Koeln Fuesse Oel Uebel Aeue Uess AEOEUe Ae Oe Ue UEBUNG"
     * @param input
     * @return the input string with replaces umlaute
     */
    private static String replaceUmlaut(String input) {

        //replace all lower Umlauts
        String o_strResult =
                input
                .replaceAll("ü", "ue")
                .replaceAll("ö", "oe")
                .replaceAll("ä", "ae")
                .replaceAll("ß", "ss");

        //first replace all capital umlaute in a non-capitalized context (e.g. Übung)
        o_strResult =
                o_strResult
                .replaceAll("Ü(?=[a-zäöüß ])", "Ue")
                .replaceAll("Ö(?=[a-zäöüß ])", "Oe")
                .replaceAll("Ä(?=[a-zäöüß ])", "Ae");

        //now replace all the other capital umlaute
        o_strResult =
                o_strResult
                .replaceAll("Ü", "UE")
                .replaceAll("Ö", "OE")
                .replaceAll("Ä", "AE");

        return o_strResult;
    }

“Käse Köln Füße Öl Übel Äü Üß ÄÖÜ Ä Ö Ü ÜBUNG” will become: “Kaese Koeln Fuesse Oel Uebel Aeue Uess AEOEUe Ae Oe Ue UEBUNG”