31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

√<br />

y v = b 1 c 2 + b 2 c 1 ± sign(r) 2c 1 c 2 ( √ N − D)<br />

z v = √ N − a 1 a 2 − b 1 b 2<br />

and<br />

s = b 1 D 2 − b 2 D 1 , N = (a 2 1 + b2 1 )(a2 2 + b2 2 )<br />

r = a 1 D 2 − a 2 D 1 , D = a 1 a 2 − b 1 b 2 .<br />

Let us concentrate on one of these (say, we take the plus sign in both cases). <strong>The</strong> test<br />

whether l 3 intersects, touches or misses the circle amounts to determining the sign of<br />

E := dist 2 (v, l 3 ) − dist 2 (v, p) = (a 3x v + b 3 y v + c 3 ) 2<br />

a 2 3 + b 2 3<br />

− (x 2 v + y2 v ).<br />

<strong>The</strong> following program computes the sign of Ẽ := (a2 3 + b2 3 ) · E using our data type real.<br />

int incircle( real a 1 , real b 1 , real c 1 , real a 2 , real b 2 , real c 2 , real a 3 , real b 3 ,<br />

real c 3 )<br />

{<br />

real RN = sqrt((a 1 ∗ a 1 + b 1 ∗ b 1 ) ∗ (a 2 ∗ a 2 + b 2 ∗ b 2 ));<br />

real RN 1 = sqrt(a 1 ∗ a 1 + b 1 ∗ b 1 );<br />

real RN 2 = sqrt(a 2 ∗ a 2 + b 2 ∗ b 2 );<br />

real A = a 1 ∗ c 2 + a 2 ∗ c 1 ;<br />

real B = b 1 ∗ c 2 + b 2 ∗ c 1 ;<br />

real C = 2 ∗ c 1 ∗ c 2 ;<br />

real D = a 1 ∗ a 2 − b 1 ∗ b 2 ;<br />

real s = b 1 ∗ RN 2 − b 2 ∗ RN 1 ;<br />

real r = a 1 ∗ RN 2 − a 2 ∗ RN 1 ;<br />

int sign x = sign(s);<br />

int sign y = sign(r);<br />

real x v = A + sign x ∗ sqrt(C ∗ (RN + D));<br />

real y v = B − sign y ∗ sqrt(C ∗ (RN − D));<br />

real z v = RN − (a 1 ∗ a 2 + b 1 ∗ b 2 );<br />

real P = a 3 ∗ x v + b 3 ∗ y v + c 3 ∗ z v ;<br />

real D 2 3 = a 3 ∗ a 3 + b 3 ∗ b 3 ;<br />

real R 2 = x v ∗ x v + y v ∗ y v ;<br />

real E = P ∗ P − D 2 3 ∗ R2 ;<br />

return sign(E);<br />

}<br />

We can make the above program more efficient if all coefficients a i , b i and c i , 1 ≤ i ≤ 3,<br />

are k bit integers, i.e., integers whose absolute value is bounded by 2 k − 1. In [17, 14] we<br />

showed that for Ẽ ≠ 0 we have |Ẽ| ≥ 2−24k−26 . Hence we may add a parameter int k in<br />

the above program and replace the last line by<br />

return E.sign(24 ∗ k + 26).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!