Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- def VSum(*VectorArgs):
- if len(VectorArgs) == 1:
- Vectors = VectorArgs[0]
- else:
- Vectors = VectorArgs
- Result = tuple(Vectors[0])
- for i in range(1, len(Vectors)):
- Result = tuple(a + b for a, b in zip(Result, Vectors[i]))
- return Result
- def VDiff(A, B):
- return tuple(x - y for x, y in zip(A, B))
- def VLengthSquared(A):
- return sum(x * x for x in A)
- def VLength(A):
- return sqrt(VLengthSquared(A))
- def VScaled(A, Scale):
- return tuple(x * Scale for x in A)
- def VPerp(A):
- return (-A[1], A[0])
- def CentredArcFromArcSweep(P1, P2, SweepAngle):
- circle = 2.0 * pi
- Diff = VDiff(P2, P1)
- Dist = VLength(Diff)
- s = sin(0.5 * SweepAngle)
- Radius = Dist / (2.0 * s)
- M = VScaled(VSum(P1, P2), 0.5)
- t = tan(0.5 * SweepAngle)
- Centre = VSum(M, VPerp(VScaled(Diff, 0.5 / t)))
- R1 = VDiff(P1, Centre)
- StartAngle = atan2(R1[1], R1[0])
- EndAngle = StartAngle + SweepAngle
- EndAngle = ((EndAngle + pi) % circle) - pi
- return Centre, Radius, StartAngle, EndAngle
- def Main():
- P1 = (0.7071, 2.0 - 0.7071)
- P2 = (0.7071, 2.0 + 0.7071)
- Angle = radians(90.0)
- print "Start point, end point and (signed) sweep angle:"
- print P1, P2, degrees(Angle)
- Centre, Radius, StartAngle, EndAngle = CentredArcFromArcSweep(P1, P2, Angle)
- print "Centre, radius and start and end angles:"
- print Centre, Radius, degrees(StartAngle), degrees(EndAngle)
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement