A circular motion around a circular object

1. This is the wrong version, program 1

Under semicircle, just look down at the semicircle. y = - square root (2 * R - X squared); then, the motion is Caton, so I for a program.

Code x can control the speed of movement of the horizontal axis

 var x = 0,y;
        var r = 200;
        var isBack = false;
        var speed = 0.5;
        function render(){
            if(pivot){
                if(!isBack){
                    x = x + speed;
                    y = Math.sqrt(2*r*x -x*x);
                    if(x == 2*r) isBack = true;
                }
                else{
                    isBack = true;
                    x = x - speed;
                    y = -Math.sqrt(2*r*x -x*x);
                    if(x == 0){
                        isBack = false;
                    }
                }
                mesh.position.x = y;
                mesh.position.y = x;
            }
            renderer.clear();
            renderer.render( scene, camera );
      

Guess you like

Origin www.cnblogs.com/chenyi4/p/12482594.html