← Back to topics
Topic

z-radar

r
robi_petranovic
How did you calculate line-point distance?

I tried it on my own (using Heron's formula, and v = 2 * P / |AB|), but i get WA for all (even for test case)

Then I used the code from topcoder tutorial (using dot and cross product of vectors), and test case is correct, but again, everything else is WA....
i
iggy91
I used dot i cross product and I got it done. Check the correctness of the rest of your algorithm.

Sort the array with line-point distance function as comparation function and Kth element of sorted array is the solution. (actually, distance of Kth line from given point)
r
robi_petranovic
aha, tnx.... I've just noticed I had bad vector calculations... tnx for your help
T
Tavo92
I got a big help from this article: http://www.topcoder.com/tc?module=Static&d1=tutorials&d2=geometry1
d
demjan0001
you don't need to know vectors to do that ...
you need to know just that k of normal line is (-1)/k ...