def bisectoare(p1, p2, p3):
d1, d2 = abs(p2 - p3), abs(p1 - p3)
return (p1 * d1 + p2 * d2) / (d1 + d2)
def triunghi_bisectoare():
C.setXminXmaxYminYmax(-10, 10, -10, 10)
A = complex(-9, -4)
B = complex(6, -4)
D = complex(0, 6)
I = (A + B + D) / 3
b1 = bisectoare(A, B, D)
b2 = bisectoare(B, D, A)
b3 = bisectoare(D, A, B)
for z in C.screenAffixes():
x, y = z.real, z.imag
cond1 = (y - A.imag) * (I.real - A.real) - (x - A.real) * (I.imag - A.imag) > 0
cond2 = (y - B.imag) * (I.real - B.real) - (x - B.real) * (I.imag - B.imag) > 0
cond3 = (y - D.imag) * (I.real - D.real) - (x - D.real) * (I.imag - D.imag) > 0
if cond1 and cond2 and cond3:
col = Color.Yellow
elif cond1 and cond2:
col = Color.Cyan
elif cond2 and cond3:
col = Color.Magenta
elif cond1 and cond3:
col = Color.Orange
elif cond1:
col = Color.Green
elif cond2:
col = Color.Blue
else:
col = Color.Red
C.setPixel(z, col)
C.drawLine(A, B, Color.Black)
C.drawLine(B, D, Color.Black)
C.drawLine(D, A, Color.Black)
C.refreshScreen()
ZGVmIGJpc2VjdG9hcmUocDEsIHAyLCBwMyk6CiAgICBkMSwgZDIgPSBhYnMocDIgLSBwMyksIGFicyhwMSAtIHAzKQogICAgcmV0dXJuIChwMSAqIGQxICsgcDIgKiBkMikgLyAoZDEgKyBkMikKCmRlZiB0cml1bmdoaV9iaXNlY3RvYXJlKCk6CiAgICBDLnNldFhtaW5YbWF4WW1pblltYXgoLTEwLCAxMCwgLTEwLCAxMCkKCgogICAgQSA9IGNvbXBsZXgoLTksIC00KQogICAgQiA9IGNvbXBsZXgoNiwgLTQpCiAgICBEID0gY29tcGxleCgwLCA2KQoKCgoKICAgIEkgPSAoQSArIEIgKyBEKSAvIDMKCiAgICBiMSA9IGJpc2VjdG9hcmUoQSwgQiwgRCkKICAgIGIyID0gYmlzZWN0b2FyZShCLCBELCBBKQogICAgYjMgPSBiaXNlY3RvYXJlKEQsIEEsIEIpCgoKCgogICAgZm9yIHogaW4gQy5zY3JlZW5BZmZpeGVzKCk6CiAgICAgICAgeCwgeSA9IHoucmVhbCwgei5pbWFnCiAgICAgICAgY29uZDEgPSAoeSAtIEEuaW1hZykgKiAoSS5yZWFsIC0gQS5yZWFsKSAtICh4IC0gQS5yZWFsKSAqIChJLmltYWcgLSBBLmltYWcpID4gMAogICAgICAgIGNvbmQyID0gKHkgLSBCLmltYWcpICogKEkucmVhbCAtIEIucmVhbCkgLSAoeCAtIEIucmVhbCkgKiAoSS5pbWFnIC0gQi5pbWFnKSA+IDAKICAgICAgICBjb25kMyA9ICh5IC0gRC5pbWFnKSAqIChJLnJlYWwgLSBELnJlYWwpIC0gKHggLSBELnJlYWwpICogKEkuaW1hZyAtIEQuaW1hZykgPiAwCgogICAgICAgIGlmIGNvbmQxIGFuZCBjb25kMiBhbmQgY29uZDM6CiAgICAgICAgICAgIGNvbCA9IENvbG9yLlllbGxvdwogICAgICAgIGVsaWYgY29uZDEgYW5kIGNvbmQyOgogICAgICAgICAgICBjb2wgPSBDb2xvci5DeWFuCiAgICAgICAgZWxpZiBjb25kMiBhbmQgY29uZDM6CiAgICAgICAgICAgIGNvbCA9IENvbG9yLk1hZ2VudGEKICAgICAgICBlbGlmIGNvbmQxIGFuZCBjb25kMzoKICAgICAgICAgICAgY29sID0gQ29sb3IuT3JhbmdlCiAgICAgICAgZWxpZiBjb25kMToKICAgICAgICAgICAgY29sID0gQ29sb3IuR3JlZW4KICAgICAgICBlbGlmIGNvbmQyOgogICAgICAgICAgICBjb2wgPSBDb2xvci5CbHVlCiAgICAgICAgZWxzZToKICAgICAgICAgICAgY29sID0gQ29sb3IuUmVkCgogICAgICAgIEMuc2V0UGl4ZWwoeiwgY29sKQoKICAgIEMuZHJhd0xpbmUoQSwgQiwgQ29sb3IuQmxhY2spCiAgICBDLmRyYXdMaW5lKEIsIEQsIENvbG9yLkJsYWNrKQogICAgQy5kcmF3TGluZShELCBBLCBDb2xvci5CbGFjaykKICAgIEMucmVmcmVzaFNjcmVlbigpCg==