Skip to content

Instantly share code, notes, and snippets.

@mauriciopoppe
Last active May 24, 2016 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauriciopoppe/1a54c71953a74c372d43fd7f55194282 to your computer and use it in GitHub Desktop.
Save mauriciopoppe/1a54c71953a74c372d43fd7f55194282 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
import qh from 'quickhull3d'
import util from 'util'
const vertices = [
[ 0.9510565162951535, -0.3090169943749474, 0 ],
[ 0.5877852522924731, -0.8090169943749475, 0 ],
[ 6.123233995736766e-17, -1, 0 ],
[ -0.5591929034707466, 0.8290375725550418, 0 ],
[ -0.9510565162951535, -0.3090169943749475, 0 ],
[ -0.9510565162951536, 0.3090169943749473, 0 ],
[ -0.5877852522924732, 0.8090169943749473, 0 ],
[ -1.8369701987210297e-16, 1, 0 ],
[ 0.5877852522924729, 0.8090169943749476, 0 ],
[ 0.9510565162951535, 0.3090169943749476, 0 ],
[ 0.984807753012208, 0, -0.17364817766693033 ],
[ 0.30432233187297814, -0.9366078308002486, -0.17364817766693033 ],
[ -0.796726208379082, -0.5788554735638644, -0.17364817766693033 ],
[ -0.7967262083790821, 0.5788554735638641, -0.17364817766693033 ],
[ 0.3043223318729779, 0.9366078308002487, -0.17364817766693033 ],
[ 0.5000000000000001, -0.5, 0.7071067811865475 ],
[ -0.5, -0.5000000000000001, 0.7071067811865475 ],
[ -0.5000000000000001, 0.5, 0.7071067811865475 ],
[ 0.4999999999999999, 0.5000000000000001, 0.7071067811865475 ],
[ 6.123233995736766e-17, 0, 1 ]
]
let faces = qh(vertices)
// push first element until the lowest index is first
function sortVerticesInFace(face) {
const min = Math.min.apply(Math, face)
while (face[0] !== min) {
face.push(face.shift())
}
return face
}
faces = faces.map(sortVerticesInFace)
faces.sort((a, b) => {
if (a[0] !== b[0]) return a[0] - b[0]
if (a[1] !== b[1]) return a[1] - b[1]
return a[2] - b[2]
})
console.log(util.inspect(faces))
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"quickhull3d": "2.0.0",
"undefined": "v0.10.26"
}
}
'use strict';
var _quickhull3d = require('quickhull3d');
var _quickhull3d2 = _interopRequireDefault(_quickhull3d);
var _util = require('util');
var _util2 = _interopRequireDefault(_util);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var vertices = [[0.9510565162951535, -0.3090169943749474, 0], [0.5877852522924731, -0.8090169943749475, 0], [6.123233995736766e-17, -1, 0], [-0.5591929034707466, 0.8290375725550418, 0], [-0.9510565162951535, -0.3090169943749475, 0], [-0.9510565162951536, 0.3090169943749473, 0], [-0.5877852522924732, 0.8090169943749473, 0], [-1.8369701987210297e-16, 1, 0], [0.5877852522924729, 0.8090169943749476, 0], [0.9510565162951535, 0.3090169943749476, 0], [0.984807753012208, 0, -0.17364817766693033], [0.30432233187297814, -0.9366078308002486, -0.17364817766693033], [-0.796726208379082, -0.5788554735638644, -0.17364817766693033], [-0.7967262083790821, 0.5788554735638641, -0.17364817766693033], [0.3043223318729779, 0.9366078308002487, -0.17364817766693033], [0.5000000000000001, -0.5, 0.7071067811865475], [-0.5, -0.5000000000000001, 0.7071067811865475], [-0.5000000000000001, 0.5, 0.7071067811865475], [0.4999999999999999, 0.5000000000000001, 0.7071067811865475], [6.123233995736766e-17, 0, 1]];
var faces = (0, _quickhull3d2.default)(vertices);
// push first element until the lowest index is first
function sortVerticesInFace(face) {
var min = Math.min.apply(Math, face);
while (face[0] !== min) {
face.push(face.shift());
}
return face;
}
faces = faces.map(sortVerticesInFace);
faces.sort(function (a, b) {
if (a[0] !== b[0]) return a[0] - b[0];
if (a[1] !== b[1]) return a[1] - b[1];
return a[2] - b[2];
});
console.log(_util2.default.inspect(faces));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment