Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created March 25, 2017 13:52
Show Gist options
  • Save ikr7/6fb6a0dd648ae65d43dcb0ecbf059e67 to your computer and use it in GitHub Desktop.
Save ikr7/6fb6a0dd648ae65d43dcb0ecbf059e67 to your computer and use it in GitHub Desktop.
計算です
// これ ( https://www.desmos.com/calculator/ktrb025zjm ) と半直線との交点を求める
// 楕円は this, 楕円の各パラメータは desmos に準じる, ただし desmos での t は theta とした
// 半直線は r, 原点は o, 方向ベクトルは d
const A: number = // t^2の係数
(Math.cos(this.theta) ** 2 * r.d.x ** 2) / this.b ** 2 +
(Math.cos(this.theta) ** 2 * r.d.y ** 2) / this.d ** 2 +
(2 * Math.cos(this.theta) * r.d.x * r.d.y * Math.sin(this.theta)) / this.b ** 2 +
(2 * Math.cos(this.theta) * r.d.x * r.d.y * Math.sin(this.theta)) / this.d ** 2 +
(r.d.x ** 2 * Math.sin(this.theta) ** 2) / this.d ** 2 +
(r.d.y ** 2 * Math.sin(this.theta) ** 2) / this.b ** 2;
const B: number = // tの係数
-((2 * this.a * Math.cos(this.theta) * r.d.x) / this.b ** 2)-
(2 * this.c * Math.cos(this.theta) * r.d.y) / this.d ** 2 +
(2 * Math.cos(this.theta) ** 2 * r.d.x * r.o.x) / this.b ** 2 +
(2 * Math.cos(this.theta) ** 2 * r.d.y * r.o.y) / this.d ** 2 -
(2 * this.c * r.d.x * Math.sin(this.theta)) / this.d ** 2 -
(2 * this.a * r.d.y * Math.sin(this.theta)) / this.b ** 2 +
(2 * Math.cos(this.theta) r.d.y * r.o.x * Math.sin(this.theta)) / this.b ** 2 +
(2 * Math.cos(this.theta) r.d.y * r.o.x * Math.sin(this.theta)) / this.d ** 2 +
(2 * Math.cos(this.theta) r.d.x * r.o.y * Math.sin(this.theta)) / this.b ** 2 +
(2 * Math.cos(this.theta) r.d.x * r.o.y * Math.sin(this.theta)) / this.d ** 2 +
(2 * r.d.x * r.o.x * Math.sin(this.theta) ** 2) / this.d ** 2 +
(2 * r.d.y * r.o.y * Math.sin(this.theta) ** 2) / this.b ** 2;
const C: number = // 定数項
-1 + this.a ** 2 / this.b ** 2 + this.c ** 2 / this.d ** 2 -
(2 * this.a * Math.cos(this.theta) * r.o.x) / this.b ** 2 +
(Math.cos(this.theta) ** 2 * r.o.x ** 2) / this.b ** 2 -
(2 * this.c * Math.cos(this.theta) * r.o.y) / this.d ** 2 +
(Math.cos(this.theta) ** 2 * r.o.y ** 2) / this.d ** 2 -
(2 * this.c * r.o.x * Math.sin(this.theta)) / this.d ** 2 -
(2 * this.a * r.o.y * Math.sin(this.theta)) / this.b ** 2 +
(2 * cos * r.o.x * r.o.y * Math.sin(this.theta)) / this.b ** 2 +
(2 * cos * r.o.x * r.o.y * Math.sin(this.theta)) / this.d ** 2 +
(r.o.x ** 2 * sin ** 2) / this.d ** 2 +
(r.o.y ** 2 * sin ** 2) / this.b ** 2;
//判別式
const discriminant: number = B ** 2 - 4 * A * C;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment