1 Star 0 Fork 0

jimgo/Three Plus One Game

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Quaternion.js 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
jimgo 提交于 2021-08-09 23:44 . Rectify Wrong Quaternion Algorithm
/*
class Quaternion {
constructor(c,i,j,k){
this.c = c;
this.i = i;
this.j = j;
this.k = k;
}
mutiply(q){
return new Quaternion(
this.c * q.c - this.i * q.i - this.j * q.j - this.k * q.k,
this.c * q.i + this.i * q.c + this.j * q.k - this.k * q.j,
this.c * q.j - this.i * q.k + this.j * q.c + this.k * q.i,
this.c * q.k + this.i * q.j - this.j * q.i + this.k * q.c
)
}
}
*/
class Quaternion_str {
constructor(c, i, j, k) {
this.c = c;
this.i = i;
this.j = j;
this.k = k;
}
/**
*
* @param {Quaternion_str} q
* @returns Array<Array<String>(4)>(4)
*/
mutiply_array(q) {
return [
[['+', this.c, q.c], ['-', this.i, q.i], ['-', this.j, q.j], ['-', this.k, q.k]],
[['+', this.c, q.i], ['+', this.i, q.c], ['+', this.j, q.k], ['-', this.k, q.j]],
[['+', this.c, q.j], ['-', this.i, q.k], ['+', this.j, q.c], ['+', this.k, q.i]],
[['+', this.c, q.k], ['+', this.i, q.j], ['-', this.j, q.i], ['+', this.k, q.c]]
]
}
}
/*
0 3 1 4 2 5 n
0 0 0 3 3 1 1
1 0 0 3 3 1 1
2 0 0 3 3 1 1
3 4 4 2 2 5 5
4 4 4 2 2 5 5
5 4 4 2 2 5 5
p
*/
const Cors = [
[0, 0, 3, 3, 1, 1],
[0, 0, 3, 3, 1, 1],
[0, 0, 3, 3, 1, 1],
[4, 4, 2, 2, 5, 5],
[4, 4, 2, 2, 5, 5],
[4, 4, 2, 2, 5, 5],
];
const Hexs = [], Muts = [], Eqls = [];
for (let m = 0; m <= 5; m++) {
Hexs.push(new Quaternion_str(`c${m}`, `i${m}`, `j${m}`, `k${m}`));
}
for (let m = 0; m <= 5; m++) {
for (let n = 0; n <= 5; n++) {
// Muts.push(Hexs[m].mutiply_array(Hexs[n]));
Muts.push(
new Quaternion_str(...
Hexs[m].mutiply_array(Hexs[n]).map(
e => e.map(
d => d.sort().join('')
).join('')
)
)
);
Eqls.push(Hexs[Cors[m][n]]);
}
}
const cijk = ['c','i','j','k']
const Equations = [];
for (let x = 0; x < 36; x++) {
for(let l of cijk){
Equations.push(`${Muts[x][l]} == ${Eqls[x][l]}`);
}
}
for (const e of Equations) {
console.log(e)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jimgo/ThreePlusOneGame.git
git@gitee.com:jimgo/ThreePlusOneGame.git
jimgo
ThreePlusOneGame
Three Plus One Game
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385