unity-game-engineellipsedrawellipse

Unity Draw Ellipse at an angle


This one has me stumped.

I've got code to draw ellipses etc in Unity. It all works great. But at the moment I only get horizontal ellipses or vertical ellipses by changing the major and minor axes.

What I really need is to be able to draw ellipses at angle, tilted, skewiff, NOT straight up or sideways.

Please help. Even better if it can be done using standard draw ellipse code.


Solution

  • I don't know how do you draw ellipses because you haven't post any code but this is how you can calculate points on tilted ellipse

    var resolution = 50; //resolution of ellipse
    var a = 50;
    var b = 20;
    var rotation = Quaternion.Euler(45,0,0); //set your angles here
    for(var i = 0f; i < 2*Mathf.PI; i+=2*Mathf.PI/resolution){
        var vector = new Vector3( a*Mathf.Cos(i) ,0, b*Mathf.Sin(i) );
        vector = rotation*vector; // you can multiply vector by quaternion to get tilted ellipse
    
        //you can do something with vector here
    
    }