Skip to content

Instantly share code, notes, and snippets.

@ikekou
ikekou / gist:5559115
Last active December 17, 2015 05:38
[Math][JavaScript][CoffeeScript]各々2点を通る線分2本の交点を求める。交差してなかったらnullが戻る。(参考:http://mf-atelier.sakura.ne.jp/mf-atelier/modules/tips/index.php/program/algorithm/a1.html
cross2=(x1,y1,x2,y2,x3,y3,x4,y4)->
ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
eta = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1)
delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
ramda = ksi / delta
mu = eta / delta
if ramda >= 0 and ramda <= 1 and mu >= 0 and mu <= 1
x = x1 + ramda * (x2 - x1)
@ikekou
ikekou / gist:5559123
Last active December 17, 2015 05:38
[Math][JavaScript][CoffeeScript]座標(p1x,p1y)と(p2x,p2y)の距離を求める
getDistance:(p1x,p1y,p2x,p2y)->
dx=p1x-p2x
dy=p1y-p2y
return Math.sqrt(dx*dx+dy*dy)
@ikekou
ikekou / Main.coffee
Last active December 17, 2015 05:38
[Math][JavaScript][CoffeeScript] 3次ベジェ曲線を2次ベジェ曲線に変換する(近似するだけ、間違ってたり無駄のある可能性は十分にあり) 参考:http://www.noids.tv/2007/02/bspline_10fd.html
window.onlaod=()->
a1x=100
a1y=100
c1x=200
c1y=200
c2x=300
c2y=200
a2x=400
a2y=100
result=[]
@ikekou
ikekou / gist:5559116
Created May 11, 2013 06:41
[MovableType] htmlを削除して出力
<$MTEntryTitle remove_html="1"$>
@ikekou
ikekou / gist:5559127
Last active December 17, 2015 05:39
[Math][JavaScript][CoffeeScript]2次ベジェ曲線の中間点の座標を求める
#2次ベジェの中間点の座標を求める
#a1はアンカーポイント1
#c1はアンカーポイント1から出るコントロールポイント
#c2はアンカーポイント2から出るコントロールポイント
#a2はアンカーポイント2
#tは分割する割合、0~1の範囲
getQuadraticBezierPoint:(a1x,a1y,cx,cy,a2x,a2y,t)->
tp = 1 - t
x = t*t*a2x + 2*t*tp*cx + tp*tp*a1x
y = t*t*a2y + 2*t*tp*cy + tp*tp*a1y
@ikekou
ikekou / gist:5559092
Last active December 17, 2015 05:39
[Math][JavaScript][CoffeeScript]各々2点を通る直線2本の交点を求める(参考:http://mf-atelier.sakura.ne.jp/mf-atelier/modules/tips/index.php/program/algorithm/a1.html
cross=(x1,y1,x2,y2,x3,y3,x4,y4)->
ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
ramda = ksi / delta
x = x1 + ramda * (x2 - x1)
y = y1 + ramda * (y2 - y1)
return [x,y]
@ikekou
ikekou / gist:5559118
Created May 11, 2013 06:42
[MovableType] MT4.xでカテゴリー関連記事表示
<MTSetVarBlock name="catList"><MTEntryCategories glue=" OR "><$MTCategoryLabel$></MTEntryCategories></MTSetVarBlock>
<MTSetVarBlock name="baseTitle"><$MTEntryTitle$></MTSetVarBlock>
<h2>関連記事</h2>
<ul>
<MTEntries lastn="6" categories="$catList">
<MTSetVarBlock name="relatedTitle"><$MTEntryTitle$></MTSetVarBlock>
<MTIf name="relatedTitle" ne="$baseTitle">
<li><a href="<$MTEntryLink$>"><$MTEntryTitle$></a></li>
</MTIf>
</MTEntries>
@ikekou
ikekou / gist:5559128
Last active December 17, 2015 05:39
[Math][JavaScript][CoffeeScript] 座標(p1x,p2y)と座標(p2x,p2y)を結ぶ線分をt:1-tで分割した座標を求める
#座標(p1x,p2y)と座標(p2x,p2y)を結ぶ線分をt:1-tで分割した座標を求める
interpolate:(p1x,p1y,p2x,p2y,t)->
return [
p1x+(p2x-p1x)*t,
p1y+(p2y-p1y)*t
]
@ikekou
ikekou / gist:5588434
Last active December 17, 2015 09:38
[Math][JavaScript][CoffeeScript] 2点を通る直線と円の交点を求める
#直線の座標A、直線の座標、円の中心点の座標、円の半径
getPointsOfIntersectionWithLineAndCircle=(aX,aY,bX,bY,cX,cY,r)->
a = bY - aY
b = aX - bX
c = -( a*aX + b*aY )
l = Math.sqrt((bX-aX)*(bX-aX)+(bY-aY)*(bY-aY))
eX = (bX - aX) / l
@ikekou
ikekou / Config.coffee
Last active December 17, 2015 09:39
[JavScript][CoffeeScript] dat.GUIマイテンプレ
class Config
_instance = null
constructor:()->
throw new Error 'Cant create instance, use \'getInstance\'.'
@getInstance: () ->
_instance ?= new _PrivateClass()
class _PrivateClass
str:'some string !'