zoukankan      html  css  js  c++  java
  • 魔方旋转基础模型

    //魔方旋转基础模型
    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)
    

      

  • 相关阅读:
    linux命令整理
    各种提权姿势总结
    常用端口信息说明和利用
    近年来爆发的CVE漏洞编号
    一个优秀的SSH远程终端工具
    python-读写文件的方式
    kali安装ssh服务
    一套实用的渗透测试岗位面试题
    使用 python快速搭建http服务
    asciinema使用
  • 原文地址:https://www.cnblogs.com/caoke/p/10205198.html
Copyright © 2011-2022 走看看