Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created September 5, 2013 11:58
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 zeffii/6449183 to your computer and use it in GitHub Desktop.
Save zeffii/6449183 to your computer and use it in GitHub Desktop.
quick_bisectors

[ Launch: coffee_template ] 6449183 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6399870 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382272 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6382237 by zeffii
[ Launch: boomstick_motion_wcolor_coffee ] 6379220 by zeffii
[ Launch: boomstick_motion_wcolor ] 6376715 by zeffii
[ Launch: boomstick_motion2 ] 6365156 by zeffii
[ Launch: boomstick_motion ] 6364686 by zeffii
[ Launch: boomstick ] 6364584 by zeffii
[ Launch: zeffii default ] 6364028 by zeffii
[ Launch: zeffii default ] 5033869 by zeffii

{"description":"quick_bisectors","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"style.css":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data2.csv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"util.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"injet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12},"utils.coffee":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/OqFYJQH.png"}
tributary.tolist = (points...) ->
plist = []
for p in points
for c in [p.x, p.y]
plist.push c
plist
CCI = tributary.circle_circle_intersection
#tributary.from3points = (points...) ->
# [a,b,c] = points
get_points = (angle, amp) ->
x: Math.cos(angle) * amp
y: Math.sin(angle) * amp
tolist = tributary.tolist
d3.select("body").style "background-color", d3.rgb(25, 25, 25)
svg = d3.select("svg")
group1 = svg.append("g").classed("group1", true)
group1
.attr("transform", "translate(" + [37, 150] + ")")
.style
fill: "none"
stroke: "#aeaeae"
dots = [
{x: 26, y: 70, col: '#ae1283'}, # maroon
{x: 366, y: 14, col: '#A8A8A8'}, # grey
{x: 211, y: 291, col: '#1FFF00'},] # green
[p0, p1] = CCI(dots[0], 200, dots[1], 200)
group1.append('path')
.attr
'd': 'M' + tolist(p0, p1)
balls = group1.selectAll('circle').data(dots)
balls.enter()
.append('circle')
.attr
r: 5.0
transform: (d) -> "translate(" + [d.x, d.y] + ")"
.style
fill: (d) -> d.col
group1.append("path")
.style
'fill': '#DAF6FF'
'fill-opacity': 0.136752
'stroke': '#D690AF'
'stroke-width': 1.16
'stroke-dasharray': "5,5"
.attr
'd': 'M' + tolist(dots...) + 'z'
.cm-s-elegant.CodeMirror { background: #1e2426; color: #696969; }
.cm-s-elegant div.CodeMirror-selected {background: #064968 !important;} /* 33322B*/
.cm-s-elegant span.cm-variable { color:#22EFFF; }
.cm-s-elegant span.cm-variable-2 { color: #FFCCB4; }
.cm-s-elegant span.cm-variable-3 { color: white; }
.cm-s-elegant span.cm-string { color: Chartreuse; }
.cm-s-elegant span.cm-string-2 {color: Chartreuse;}
.cm-s-elegant span.cm-def {color: #FFCCB4; opacity: 1.0}
.cm-s-elegant span.cm-bracket { color: #EBEFE7; }
.cm-s-elegant pre { color:#FFF; }
.cm-s-elegant span.cm-qualifier { color:#C0C0C0; }
.cm-s-elegant span.cm-comment { color: #AFB4B4;}
.cm-s-elegant span.cm-property {color: #FDA676;}
.cm-s-elegant span.cm-number { color: #FF92EE;}
.cm-s-elegant span.cm-keyword { color: #FFFF18; }
.cm-s-elegant .CodeMirror-cursor { border-left: 1px solid white !important; }
.cm-s-elegant .CodeMirror-gutters {background: #505050;}
.cm-s-elegant .CodeMirror-linenumber {color: #D3D3D3;}
tributary.circle_circle_intersection = (p0, r0, p1, r1) ->
# literal translation of
# http://paulbourke.net/geometry/circlesphere/tvoght.c
# dx and dy are the x, y distances between the circle centers.
[x0, y0] = [p0.x, p0.y]
[x1, y1] = [p1.x, p1.y]
[dx, dy] = [x1 - x0, y1 - y0]
# Determine the straight-line distance between the centers.
# d = hypot(dx,dy); // Suggested by Keith Briggs
d = Math.sqrt((dy*dy) + (dx*dx));
# Check for solvability. quit early
return None if (d > (r0 + r1)) or (d < Math.abs(r0 - r1))
# the distance from point 0 to point 2.
a = ((r0*r0) - (r1*r1) + (d*d)) / (2.0 * d) ;
# coordinates of point 2.
x2 = x0 + (dx * a/d);
y2 = y0 + (dy * a/d);
# distance from point 2 to either of the intersection points.
h = Math.sqrt((r0*r0) - (a*a));
# offsets of the intersection points from point 2.
rx = -dy * (h/d);
ry = dx * (h/d);
# absolute intersection points.
[{x: x2 + rx, y: y2 + ry}, {x: x2 - rx, y: y2 - ry}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment