python: calculate steps for dreamcatcher -
i stuck trying calculate dreamcatcher , inner circles. have outer circle given radius x
, need calculate perimeter. have calculate magic value how wide every bow (in image stuff numbers) should , should result bows not finish @ start point overlapp half bow first.
here tried far:
import math # in cm rad = 5.0 perimeter = round(rad * 2.0 * math.pi, 2) print "perimeter == %f" % perimeter #bow = "?" incvalue = 0.00001 start = incvalue end = perimeter while start < end / 10: tmp = start * 10 while tmp < perimeter: tmp += start if tmp - perimeter == start / 2: print "bow %s" % str(tmp) start += incvalue print "done"
but not able find value fits constraints.
i think can value want with
bow_length = perimeter / (desired_number_of_full_bows + 0.5)
but if you're interested in getting approximation system working, think line causing problems:
if tmp - perimeter == start / 2:
floating point numbers compare equal 1 another, conventional instead check close together. might instead do:
if abs((tmp - perimeter) - (start / 2)) < epsilon:
... epsilon
represents largest possible "wiggle room" between 2 numbers willing accept. 0.0001, although experiment larger or smaller values see works best.
Comments
Post a Comment