0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

大人用「円と三角形(正解率1%未満)和歌山県公立入試2025年度 数学 大問4(3)だけ」を、計算はsympyで、作図はFreeCADでやった。(その5/7) クォータニオンで。

Last updated at Posted at 2025-12-15

(その1/7) YUUU0123 様
(その2/7) MAスカッと塾 様
(その3/7) マイティ 様
(その4/7) 大人は分度器で。Triangle 拡張クラス。
(その5/7) 本ページ
(その6/7)複素数平面で。
(その7/7) 100通りで。

・ChatGPT先生に丸投げです。私には無理。
 これも「クォータニオン」というのかしら。

(本日の)chatGPT先生へ。

・(聞き直した回答省略)

以下の図形の問題のソースコードを、クォータニオンの行列に変換して下さい。
#### ver1.2
(ver1.2 のソースコードの表示を省略)

(途中のエラーを省略)

  1. クォータニオン行列版コード(verQ-1.2)
    ...

✅ NameError 修正版(verQ-matrix-1.2-clean)
...

なぜ NameError: Q2 が出たのか(重要)
...

???

(最終?回答コード)

# ver5.1
import sympy as sp
pi = sp.pi

# -----------------------
# 外積行列(3×3)
# -----------------------
def cross_mat(v):
    x, y, z = v
    return sp.Matrix([
        [ 0, -z,  y],
        [ z,  0, -x],
        [-y,  x,  0]
    ])

# -----------------------
# 同次点 (x,y,1)
# -----------------------
def P(x, y):
    return sp.Matrix([x, y, 1])

# -----------------------
# 直線 = P × Q
# -----------------------
def line(P1, P2):
    return cross_mat(P1) * P2

# -----------------------
# 交点 = ℓ1 × ℓ2
# -----------------------
def intersect(l1, l2):
    X = cross_mat(l1) * l2
    return X / X[2]   # 同次正規化(線形)

# -----------------------
# 距離(行列式ではなく内積)
# -----------------------
def dist(P1, P2):
    dx = P1[0] - P2[0]
    dy = P1[1] - P2[1]
    return sp.sqrt(dx*dx + dy*dy)

# =======================
# 問題本体
# =======================

r = sp.symbols('r', nonnegative=True)

O = P(0, 0)
A = P(r*sp.cos(120*pi/180), r*sp.sin(120*pi/180))
B = P(-r, 0)
C = P(0, -r)
D = P(r, 0)

# 直線(行列のみ)
BD = line(B, D)
AC = line(A, C)
AD = line(A, D)
CO = line(C, O)

# 交点(行列のみ)
E = intersect(BD, AC)
F = intersect(AD, CO)

# 条件 |AE| = 3√2
r_sol = sp.solve(
    sp.Eq(dist(A, E), 3*sp.sqrt(2)),
    r
)[0]

# 求める距離
ans = sp.sqrtdenest(
    dist(F, C).subs({r: r_sol})
).simplify()

print("#", ans)
# 2*sqrt(3) + 4

いつもと違うおすすめです。

Qiita 内

@osawat 様へ いつもお世話になっております。

sympy のdoc

ver5.1

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?