• API
• FAQ
• Tools
• Archive
daily pastebin goal
37%
SHARE
TWEET

# Fractal

a guest Mar 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def solve(f, d, pointlist, totlength, lengthlist):
2.     if f >= 1: return pointlist[-1] - pointlist[0]
3.     traversed = 0
4.     currentpoint = 0
5.     while (traversed + lengthlist[currentpoint])/totlength < f:
6.         traversed += lengthlist[currentpoint]
7.         currentpoint += 1
8.     if d == 1:
9.         return pointlist[currentpoint] + (pointlist[currentpoint+1] - pointlist[currentpoint])*(f - (traversed / totlength))/(lengthlist[currentpoint]/totlength)
10.     else:
11.         return pointlist[currentpoint] + ((pointlist[currentpoint + 1] - pointlist[currentpoint])/(pointlist[-1] - pointlist[0])) * (solve((f - (traversed/totlength))/(lengthlist[currentpoint]/totlength), d - 1, pointlist, totlength, lengthlist) - pointlist[0])
12. cases = int(input())
13. for i in range(cases):
14.     pointnum = int(input())
15.     for m in range(pointnum):
16.         p = input().split()
17.         if m == 0:
18.             points = [int(p[0]) + int(p[1])*1j]
19.             totlength = 0
20.             lengthlist = []
21.         else:
22.             points.append(int(p[0]) + int(p[1]) * 1j)
23.             lengthlist.append(abs(points[-2]-points[-1]))
24.             totlength += abs(points[-2]-points[-1])
25.     d = int(input())
26.     f = float(input())
27.     x = (solve(f,d,points, totlength, lengthlist))
28.     print(x.real, x.imag)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top