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?

「sympyのTriangleで、三角形に三角形を追加した。」自作プログラムmyTr02

Last updated at Posted at 2024-07-22

・(予定)名称 myPoinrToMatrix → myPointToMatrix  申し訳ありません。

・いつかは、作ってみたかった関数。
・tr1の[0]と[2]に、tr2を連結しています。(結局? tr1の[1]は、使っていません。)
2点に三角形をとりつけただけじゃないの?
 直線上に三角形をとりつけただけじゃないの?
 その通りです。 三角形に三角形を連結と言えば、高級に聞こえるかも。
 keywordが使えるという事で。

myTr02の使い方

・右上、tr1の[1]と[2]に、tr2を連結したい時、引数の順番をずらす。

sympyで

・直角三角形を2個組み合わせて、長方形をつくった。
class sympy.geometry.polygon.Triangle(*args, **kwargs)
https://docs.sympy.org/latest/modules/geometry/polygons.html#sympy.geometry.polygon.Triangle

from sympy import *
var('X',real=True,poitive=True)
def myMatrixToPoint(myMatrix):    
    return Point2D(myMatrix[0],myMatrix[1])
def myPoinrToMatrix(myPoint):    
    return Matrix([[myPoint.x],[myPoint.y],[1]]) 
def myTr02(tr1,tr2):
    t     =Line(tr1.args[0],tr1.args[0]+Point(1,0)).angle_between(Line(tr1.args[0],tr1.args[2]))
    myTurn=Matrix([[cos(t),-sin(t),tr1.args[0].x],[sin(t),cos(t),tr1.args[0].y],[0,0,1]])
    return Triangle(myMatrixToPoint(myTurn*myPoinrToMatrix(tr2.args[0])),
                    myMatrixToPoint(myTurn*myPoinrToMatrix(tr2.args[1])),
                    myMatrixToPoint(myTurn*myPoinrToMatrix(tr2.args[2])))
d=1
tr1=Triangle(sss=(sqrt(3),1,2))
tr2=Triangle(sss=(2,sqrt(3),1))
print("#",myTr02(tr1,tr2))
# Triangle(Point2D(0, 0), Point2D(sqrt(3), 1), Point2D(0, 1))
tr1=Triangle(sss=(sqrt(3),1,2))
tr3=Triangle(asa=(60,2,30))
print("#",myTr02(tr1,tr3))
# Triangle(Point2D(0, 0), Point2D(sqrt(3), 1), Point2D(0, 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?