Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Ruch po elipsie, ale "pochylonej", dla matematyków chyba chwilka ;]
erix
post
Post #1





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




Mam coś takiego:
Kod
var x = radius * Math.sin(degToRad(step));
var y = radius * Math.cos(degToRad(step));

to ruch po okręgu:

(IMG:http://images47.fotosik.pl/140/4109d6add456856e.png)

Kod
var x = radius * Math.sin(degToRad(step))*0.5;
var y = radius * Math.cos(degToRad(step));

po elipsie:

(IMG:http://images44.fotosik.pl/140/cdf80f6abaf258fb.png)

Ale nie mam pomysłu, w jaki sposób tę elipsę "pochylić":

(IMG:http://images48.fotosik.pl/140/6bedd0a7750dae0a.png)

Pogooglałem nieco i nigdzie nie znalazłem remedium; tylko rysowanie/torowanie po prostej elipsie. Może ktoś poratowałby wzorem/wskazówką byłego licealistę? (IMG:http://forum.php.pl/style_emoticons/default/snitch.gif)

edit:

Hmm, wymodziłem coś takiego:
Kod
var angle = 30;

//so calculate x and y (converting angle into radians)
var y = -radius * Math.cos(degToRad(step))*Math.sin(degToRad(angle));
var x = -(radius * Math.sin(degToRad(step))+y)*(1-Math.sin(degToRad(angle)));

Ale chyba nie do końca to.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
erix
post
Post #2





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




~Speedy dostał pomógła. ;]

Sportowałem to sobie pod JS.
Kod
function degToRad(angle){
        return ((angle*Math.PI)/180);
    }
    
    var speed=3;    // steps moved at once
    var angle=70;   // rotation angle
    var a = 50;     // oval dim 1°
    var b = 20;     // oval dim 2°
    var step = 0;
    
    beta = -degToRad(angle);    // angle
    sinbeta = Math.sin(beta);   // helper 1
    cosbeta = Math.cos(beta);   // helper 2
    

    function move() {
        if(step>360){
            step=0;
        }
        
        var alpha = degToRad(step)
        var sinalpha = Math.sin(alpha);
        var cosalpha = Math.cos(alpha);
        
        var x = (a*cosalpha*cosbeta-b*sinalpha*sinbeta);
        var y = (a*cosalpha*sinbeta+b*sinalpha*cosbeta);

        document.getElementById('point').style.left = (100+x)+'px';
        document.getElementById('point').style.top = (95+y)+'px';
        step += speed;

    }


    window.onload = function(){
        setInterval(move, 10);
    }


~dr_bonzo, czyli tak, jak jest to w tym listingu? Bo jeśli dobrze zrozumiałem, to chyba to. [;
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 23:23