• 魔方旋转基础模型


    //魔方旋转基础模型
    class Point{
        constructor(x,y,z){
            this.mapData={
                0:[1,0],
                45:[1,1],
                90:[0,1],
                135:[-1,1],
                180:[-1,0],
                225:[-1,-1],
                270:[0,-1],
                315:[1,-1],
            }
            this.oriData=[x,y,z,1,1,1]
    
        }
        //向量转值
        getAngle(x,y){
           for(let k in this.mapData){
               const arr=this.mapData[k]
               if(x==arr[0]&&y==arr[1]){
                   return Number(k);
               }
           }
        }
        //获取向量
        getPoint(angle){
            while(angle<0){
                angle=angle+360
            }
            return this.mapData[angle];
        }
        //沿x轴旋转
        translateX(angle){
    
            const [x,y,z,xp,yp,zp]=this.oriData
            const ag1=this.getAngle(y,z);
            const [y2,z2]=this.getPoint(angle+ag1)
    
            const ag2=this.getAngle(yp,zp)
            const [yp2,zp2]=this.getPoint(angle+ag2)
    
            this.oriData=[x,y2,z2,xp,yp2,zp2]
    
        }
        //沿y轴旋转
        translateY(angle){
            const [x,y,z,xp,yp,zp]=this.oriData
            const ag1=this.getAngle(z,x);
            const [z2,x2]=this.getPoint(angle+ag1)
    
            const ag2=this.getAngle(zp,xp)
            const [zp2,xp2]=this.getPoint(angle+ag2)
    
            this.oriData=[x2,y,z2,xp2,yp,zp2]
        }
        //沿z轴旋转
        translateZ(angle){
            const [x,y,z,xp,yp,zp]=this.oriData
            const ag1=this.getAngle(x,y);
            const [x2,y2]=this.getPoint(angle+ag1)
    
            const ag2=this.getAngle(xp,yp)
            const [xp2,yp2]=this.getPoint(angle+ag2)
    
            this.oriData=[x2,y2,z,xp2,yp2,zp]
        }
    }
    const p1=new Point(1,0,1)
    p1.translateX(90)
    console.log(p1.oriData)
    

      

  • 相关阅读:
    LeetCode
    在linux服务器下部署python工程(爬虫)
    linux安装python3.6 及 beautifulsoup
    HDU 1561 The more, The Better[树形dp/01背包]
    POJ 3107 Godfather[树的重心]
    POJ 1655 Balancing Act[树的重心/树形dp]
    HDU 2169 Computer[树形dp]
    HDU
    POJ1721--CARDS [置换]
    POJ 1026 Cipher[置换]
  • 原文地址:https://www.cnblogs.com/caoke/p/10205198.html
Copyright © 2020-2023  润新知