魔方吧·中文魔方俱乐部
标题:
魔方模拟器twisty-sphere
[打印本页]
作者:
怀表
时间:
2022-5-12 18:41:52
标题:
魔方模拟器twisty-sphere
本帖最后由 怀表 于 2022-5-12 23:32 编辑
https://github.com/worldmaker18349276/twisty-sphere
没有文档,我也搞不清楚是怎么自定义的。从例子看很炫酷。不过没边框很难看清块。
切割好像有两个方法sliceBySphere和sliceByPlane。不过球面切割生成魔方很慢,把resolution参数调小可提高速度。
调了半天弄出了个斜转,等明天再来试一下球面切割。
cube = CSG.cube({center: [0, 0, 0], radius: [1.1, 1.1, 1.1]})
.intersect(CSG.cube({center: [ 0,-1, 0], radius: [2, 2, 2]}).setColor(1,1,1))
.intersect(CSG.cube({center: [ 0, 1, 0], radius: [2, 2, 2]}).setColor(1,1,0))
.intersect(CSG.cube({center: [-1, 0, 0], radius: [2, 2, 2]}).setColor(0,0,1))
.intersect(CSG.cube({center: [ 1, 0, 0], radius: [2, 2, 2]}).setColor(0,1,0))
.intersect(CSG.cube({center: [ 0, 0,-1], radius: [2, 2, 2]}).setColor(1,0,0))
.intersect(CSG.cube({center: [ 0, 0, 1], radius: [2, 2, 2]}).setColor(1,0.6,0.2));
var puzzle = new ModeledSphPuzzle(cube);
puzzle.sliceByPlane([1,1,1],0)
puzzle.sliceByPlane([-1,1,1],0)
puzzle.sliceByPlane([-1,-1,1],0)
puzzle.sliceByPlane([-1,-1,-1],0)
puzzle.sliceByPlane([-1,1,-1],0)
puzzle.sliceByPlane([1,-1,1],0)
puzzle.sliceByPlane([1,-1,-1],0)
puzzle.sliceByPlane([1,1,-1],0)
puzzle.clean();
puzzle.prepare();
var world = new ModeledSphPuzzleWorld(puzzle, "display");
复制代码
2022-5-12 19:26:14 上传
下载附件
(96.32 KB)
cube = CSG.cube({center: [0, 0, 0], radius: [1.1, 1.1, 1.1]})
.intersect(CSG.cube({center: [ 0,-1, 0], radius: [2, 2, 2]}).setColor(1,1,1))
.intersect(CSG.cube({center: [ 0, 1, 0], radius: [2, 2, 2]}).setColor(1,1,0))
.intersect(CSG.cube({center: [-1, 0, 0], radius: [2, 2, 2]}).setColor(0,0,1))
.intersect(CSG.cube({center: [ 1, 0, 0], radius: [2, 2, 2]}).setColor(0,1,0))
.intersect(CSG.cube({center: [ 0, 0,-1], radius: [2, 2, 2]}).setColor(1,0,0))
.intersect(CSG.cube({center: [ 0, 0, 1], radius: [2, 2, 2]}).setColor(1,0.6,0.2));
var puzzle = new ModeledSphPuzzle(cube);
puzzle.sliceByPlane([0,1,0],0)
puzzle.sliceByPlane([1,0,1],0)
puzzle.sliceByPlane([-1,0,1],0)
puzzle.sliceByPlane([1,0,0],0)
puzzle.sliceByPlane([0,0,1],0)
puzzle.clean();
puzzle.prepare();
var world = new ModeledSphPuzzleWorld(puzzle, "display")
复制代码
2022-5-12 23:15:27 上传
下载附件
(61.45 KB)
var phi = (Math.sqrt(5) + 1)/2;
function fzy_add(set, elem) {
set.add(fzy_snap(elem, set));
}
function csort(arr0) {
var arr_min = arr0.slice();
var arr_ = arr0.slice();
for ( let i=0,len=arr0.length; i<len; i++ ) {
if ( fzy_cmp(arr_, arr_min) < 0 )
arr_min = arr_.slice();
arr_.push(arr_.shift());
}
return arr_min;
}
var radius = (phi + 1)/Math.sqrt(phi + 2);
var offset = 1;
var faces = new Set();
var vertices = [[1,1,1]];
for ( let i=0; i<4; i++ )
vertices.push(rotate(vertices[vertices.length-1], [1/2,0,1/phi/2,phi/2]));
faces.add(csort(vertices));
for ( let face of faces ) {
fzy_add(faces, csort(face.map(v => rotate(v, [1/2,1/2,1/2,1/2]))));
fzy_add(faces, csort(face.map(v => rotate(v, [1/2,0,1/phi/2,phi/2]))));
}
var polygons = [];
for ( let face of faces ) {
let polygon = new CSG.Polygon(face.map(v => new CSG.Vertex(new CSG.Vector3D(...v))));
let {x, y, z} = polygon.plane.normal;
let [r, g, b] = [x, y, z].map(v => Math.sign(v) * Math.ceil(Math.abs(v) - 0.01)).map(v => (v+1)/2);
polygon.setColor(r, g, b);
polygons.push(polygon);
}
var dodeca = CSG.fromPolygons(polygons);
var puzzle = new ModeledSphPuzzle(dodeca, radius);
puzzle.sliceByPlane([0,1,0],0)
puzzle.sliceByPlane([1,0,1],0)
puzzle.sliceByPlane([-1,0,1],0)
puzzle.sliceByPlane([1,0,0],0)
puzzle.sliceByPlane([0,0,1],0)
puzzle.clean(1);
puzzle.prepare();
var world = new ModeledSphPuzzleWorld(puzzle, "display")
复制代码
2022-5-12 23:32:19 上传
下载附件
(76.78 KB)
感觉跟胡波的正四面体切割群魔方java助手的用法有些像,不过定义多面体得手写,切割的面的法向量也得手写,调配色也很麻烦。
居然没有打乱功能。
附件:
s1-fs8.png
(2022-5-12 19:26:14, 96.32 KB) / 下载次数 58
http://bbs.mf8-china.com/forum.php?mod=attachment&aid=Mjc2OTEzfDY3ODBkYzA1fDE3MzM5NTgyODZ8MHww
附件:
s3-fs8.png
(2022-5-12 23:15:27, 61.45 KB) / 下载次数 56
http://bbs.mf8-china.com/forum.php?mod=attachment&aid=Mjc2OTE0fDJjMjU4ZmQ4fDE3MzM5NTgyODZ8MHww
附件:
s4-fs8.png
(2022-5-12 23:32:19, 76.78 KB) / 下载次数 54
http://bbs.mf8-china.com/forum.php?mod=attachment&aid=Mjc2OTE1fDUwZmFkOTQyfDE3MzM5NTgyODZ8MHww
作者:
怀表
时间:
2022-5-16 18:17:20
cube = CSG.cube({center: [0, 0, 0], radius: [1.1, 1.1, 1.1]})
.intersect(CSG.cube({center: [ 0,-1, 0], radius: [2, 2, 2]}).setColor(1,1,1))
.intersect(CSG.cube({center: [ 0, 1, 0], radius: [2, 2, 2]}).setColor(1,1,0))
.intersect(CSG.cube({center: [-1, 0, 0], radius: [2, 2, 2]}).setColor(0,0,1))
.intersect(CSG.cube({center: [ 1, 0, 0], radius: [2, 2, 2]}).setColor(0,1,0))
.intersect(CSG.cube({center: [ 0, 0,-1], radius: [2, 2, 2]}).setColor(1,0,0))
.intersect(CSG.cube({center: [ 0, 0, 1], radius: [2, 2, 2]}).setColor(1,0.6,0.2));
var puzzle = new ModeledSphPuzzle(cube);
var g = 5/3
var radius = Math.sqrt(29)/3
puzzle.sliceBySphere([ g, 0, g], radius)
puzzle.sliceBySphere([ -g,0, g], radius)
puzzle.sliceBySphere([ g,0,-g], radius)
puzzle.sliceBySphere([ -g,0,-g], radius)
puzzle.sliceByPlane([0,1,0],0)
puzzle.sliceByPlane([1,0,1],0)
puzzle.sliceByPlane([-1,0,1],0)
puzzle.clean();
puzzle.prepare();
var world = new ModeledSphPuzzleWorld(puzzle, "display");
复制代码
2022-5-16 18:17:04 上传
下载附件
(103.23 KB)
附件:
s5-fs8.png
(2022-5-16 18:17:04, 103.23 KB) / 下载次数 57
http://bbs.mf8-china.com/forum.php?mod=attachment&aid=Mjc2OTE4fDZmM2YzZjZifDE3MzM5NTgyODZ8MHww
欢迎光临 魔方吧·中文魔方俱乐部 (http://bbs.mf8-china.com/)
Powered by Discuz! X2