• 发表于 3年前
• 阅读 318
• 收藏 1
• 评论 0

图1

图2

x轴向： (sizeX, sizeY)

y轴向：(-sizeX, sizeY)

t1 = (x, y) *(sizeX, sizeY)/ ( |(x, y)|)

t2 = (x, y)*(-sizeX,  sizeY) /|(x, y)|

import math
sizeX = 135/4
sizeY = 67/4

#菱形拼图的x y 长度 和 中心位置
ab = sx1, sy1, x1, y1 = 2, 2, 0, 0
bb = sx2, sy2, x2, y2 = 2, 2, -40, 20

#求得一个拼图的左上角点和右下角点
def getBoundary(arg):
sx, sy, x, y = arg
x0 = x - (sx+sy)/2*sizeX
y0 = y - (sx+sy)/2*sizeY
x1 = x0 + sy*sizeX
y1 = y0
x2 = x0 + sx*sizeX
y2 = y0 + (sx+sy)*sizeY
print [x0, y0, x1, y1, x2, y2, sizeX, sizeY]
return [x1, y1, x2, y2]

#求得一个点在x方向的投影
def getT1(x, y):
if x == 0 and y == 0:
return 0
return (x*sizeX+y*-sizeY)/math.sqrt(x*x+y*y)/math.sqrt(sizeX*sizeX+sizeY*sizeY)
#求得一个点在y方向的投影
def getT2(x, y):
if x == 0 and y == 0:
return 0
return (x*-sizeX+y*-sizeY)/math.sqrt(x*x+y*y)/math.sqrt(sizeX*sizeX+sizeY*sizeY)
def getABound(a):
a = getBoundary(a)
t1 = getT1(a[0], a[1])
t2 = getT2(a[0], a[1])
t11 = getT1(a[2], a[3])
t22 = getT2(a[2], a[3])
print [a, t1, t2, t11, t22]
return [t1, t2, t11, t22]
def main():
aBound = getABound(ab)
bBound = getABound(bb)
print aBound
print bBound
main()

×