您当前的位置: 首页 >  Python

星夜孤帆

暂无认证

  • 3浏览

    0关注

    626博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

基于Python的matplotlib库绘制分形树

星夜孤帆 发布时间:2019-05-25 23:09:14 ,浏览量:3

import math
import copy
import numpy as np
import matplotlib.pyplot as plt
# 距离计算公式
def get_len(x1,x2,y1,y2):
    diff_x = (x1-x2)**2
    diff_y = (y1-y2)**2
    length = np.sqrt(diff_x+diff_y)
    return length
  
# 绕pointx,pointy顺时针旋转
def Srotate(angle,valuex,valuey,pointx,pointy):
  # 将角度转换为弧度
  angle = math.radians(angle)
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  sRotatex = (valuex-pointx)*math.cos(angle) + (valuey-pointy)*math.sin(angle) + pointx
  sRotatey = (valuey-pointy)*math.cos(angle) - (valuex-pointx)*math.sin(angle) + pointy
  sRotatex = sRotatex.tolist()
  sRotatey = sRotatey.tolist()
  sRotate = sRotatex + sRotatey
  sRotate = np.array(sRotate)
  return sRotate

# 绕pointx,pointy逆时针旋转
def Nrotate(angle,valuex,valuey,pointx,pointy):
  # 将角度转换为弧度
  angle = math.radians(angle)
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  nRotatex = (valuex-pointx)*math.cos(angle) - (valuey-pointy)*math.sin(angle) + pointx
  nRotatey = (valuex-pointx)*math.sin(angle) + (valuey-pointy)*math.cos(angle) + pointy
  nRotatex = nRotatex.tolist()
  nRotatey = nRotatey.tolist()
  nRotate = nRotatex + nRotatey
  nRotate = np.array(nRotate)
  return nRotate
# 判断两条线段是否相交
def judge(a,b,c,d):
  if min(a[0],b[0])            
关注
打赏
1636984416
查看更多评论
0.0423s