t | from random import random | t | from random import random |
| from math import sqrt | | from math import sqrt |
| | | |
| | | |
| def randsquare(A, B): | | def randsquare(A, B): |
| O = ((A[0] + B[0])/2, (A[1] + B[1])/2) | | O = ((A[0] + B[0])/2, (A[1] + B[1])/2) |
| | | |
| diag = (A[0] - B[0], A[1] - B[1]) | | diag = (A[0] - B[0], A[1] - B[1]) |
| diag_len = sqrt(diag[0]**2 + diag[1]**2) | | diag_len = sqrt(diag[0]**2 + diag[1]**2) |
| | | |
| diag = (diag[0]/diag_len, diag[1] / diag_len) | | diag = (diag[0]/diag_len, diag[1] / diag_len) |
| diag = (-diag[1], diag[0]) | | diag = (-diag[1], diag[0]) |
| diag_len /= 2 | | diag_len /= 2 |
| | | |
| C = (O[0] + diag[0] * diag_len, O[1] + diag[1] * diag_len) | | C = (O[0] + diag[0] * diag_len, O[1] + diag[1] * diag_len) |
| | | |
| u, v = random(), random() | | u, v = random(), random() |
| x = C[0] + u * (A[0] - C[0]) + v * (B[0] - C[0]) | | x = C[0] + u * (A[0] - C[0]) + v * (B[0] - C[0]) |
| y = C[1] + u * (A[1] - C[1]) + v * (B[1] - C[1]) | | y = C[1] + u * (A[1] - C[1]) + v * (B[1] - C[1]) |
| | | |
| return x, y | | return x, y |
| | | |