Created
April 8, 2018 01:25
-
-
Save k/c03ef2ec2164bc051544eb875e90fae2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Q4 | |
from math import pi, cos, sin, acos, asin, sqrt | |
from random import random | |
from functools import partial | |
def output(case_num, result): | |
print("Case #{}".format(case_num)) | |
for x, z, y in result: | |
print("{} {} {}".format(y, z, x)) | |
t = int(input()) | |
A_min = 1.0 | |
A_max = sqrt(3) | |
alpha_min = 0.0 | |
alpha_max = pi / 4 | |
initial_points = [(0.5, 0, 0), (0, 0.5, 0), (0, 0, 0.5)] | |
def calc_beta(A, alpha): | |
return pi / 4 + acos((A - sin(alpha)) / ( sqrt(2) * cos(alpha))) | |
def rotate_point(alpha, beta, point): | |
x, y, z = point | |
## rotate about x | |
x = x | |
y = y*cos(alpha) - y*sin(alpha) | |
z = y*sin(alpha) + z*cos(alpha) | |
## rotation about z | |
x = x*cos(beta) + y*sin(beta) | |
y = y | |
z = -x*sin(beta) + z*cos(beta) | |
return (x, y, z) | |
def area(alpha, beta): | |
return sin(alpha) + sqrt(2)*cos(alpha)*cos(beta - pi /4) | |
for case_num in range(1, t + 1): | |
A = float(input()) | |
beta = None | |
alpha = random() * pi / 4 | |
while beta is None: | |
try: | |
beta = calc_beta(A, alpha) | |
break | |
except ValueError: | |
alpha = random() * pi / 4 | |
# now that we have alpha and beta, calculate new points | |
rotate = partial(rotate_point, alpha, beta) | |
output(case_num, map(rotate, initial_points)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment