LoginSignup
1

More than 1 year has passed since last update.

posted at

【Python】数学的な変換処理まとめ(直行座標や極座標変換など)【math, numpy等】

極座標(r, Θ)から直交座標(x, y)を求める

def getXY(r, degree):
    # 度をラジアンに変換
    rad = math.radians(degree)
    x = r * math.cos(rad)
    y = r * math.sin(rad)
    print(x, y)
    return x, y

直交座標(x, y)から極座標(r, Θ)を求める

def getRD(x, y):
    r = math.sqrt(x**2+y**2)
    rad = math.atan2(y, x)
    degree = math.degrees(rad)
    print(r, degree)
    return r, degree

原点xyから特定のXYへの極座標(r, Θ)を求める

def getxy_RD(x, y, X, Y):
    _x, _y = (X-x), (Y-y)
    r = math.sqrt(_x**2+_y**2)
    rad = math.atan2(_y, _x)
    degree = math.degrees(rad)
    print(r, degree)
    return r, degree

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
What you can do with signing up
1