Created
January 21, 2019 17:24
-
-
Save bbars/6ccc69451ed538db3d0a57576eb093f3 to your computer and use it in GitHub Desktop.
Centering formula for spindle in 12-holes sphere of Spherebot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function p2d(a, r) { | |
return [ | |
r * Math.cos(a), | |
r * Math.sin(a), | |
]; | |
} | |
function p_distance(a0, r0, a1, r1) { | |
var d0 = p2d(a0, r0); | |
var d1 = p2d(a1, r1); | |
return Math.sqrt(Math.pow(d0[0] - d1[0], 2) + Math.pow(d0[1] - d1[1], 2)); | |
} | |
function p_length(p0, p1, p2, pN) { | |
var res = 0; | |
var a0 = arguments[0][0]; | |
var r0 = arguments[0][1]; | |
for (var i = 1; i < arguments.length; i++) { | |
var ai = arguments[i][0]; | |
var ri = arguments[i][1]; | |
res += p_distance(a0, r0, ai, ri); | |
} | |
return res; | |
} | |
function p_lengths(anchors, holes) { | |
var res = []; | |
for (var i = 0; i < anchors.length; i++) { | |
res[i] = p_length.apply(null, [anchors[i]].concat(holes)); | |
} | |
return res; | |
} | |
const SEG = Math.PI / 6; | |
var anchors = [ | |
/* 0 */ [0, 0], | |
/* 1 */ [0*SEG, 1], | |
/* 2 */ [0*SEG, 2], | |
/* 3 */ [1*SEG, 2], | |
/* 4 */ [1.5*SEG, 2], | |
/* 5 */ [2*SEG, 2], | |
/* 6 */ [3*SEG, 2], | |
/* 7 */ [3*SEG, 1], | |
]; | |
console.log(p_lengths(anchors, [ | |
[3*SEG, 4], | |
[7*SEG, 4], | |
[11*SEG, 4], | |
])); | |
console.log(p_lengths(anchors, [ | |
[0*SEG, 4], | |
[3*SEG, 4], | |
[6*SEG, 4], | |
[9*SEG, 4], | |
])); | |
console.log(p_lengths(anchors, [ | |
[0*SEG, 4], | |
[1*SEG, 4], | |
[2*SEG, 4], | |
[3*SEG, 4], | |
[4*SEG, 4], | |
[5*SEG, 4], | |
[6*SEG, 4], | |
[7*SEG, 4], | |
[8*SEG, 4], | |
[9*SEG, 4], | |
[10*SEG, 4], | |
[11*SEG, 4], | |
])); | |
console.log(p_lengths(anchors, [ | |
[1*SEG, 4], | |
[2*SEG, 4], | |
[4*SEG, 4], | |
[5*SEG, 4], | |
[7*SEG, 4], | |
[8*SEG, 4], | |
[10*SEG, 4], | |
[11*SEG, 4], | |
])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment