wannared's blog

By wannared, history, 7 years ago, In English

Given a Point P(x, y) find two points S1 and S2 such that S1, S2 lies on line joining origin and P and d(P, S1) = d(p, S2) = r, i.e two points that are at distance r from P.

How to get S1, S2 using minimum number of characters in C++ (CodeGolf). Codes snippets are welcome ..

Thanks in advance

  • Vote: I like it
  • -16
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it +3 Vote: I do not like it

s1=(x-rcos(h),y-rsin(h)) where tan(h)=slope of line joining origin with the point P(x,y)=y/x

s2=(x+rcos(h),y+rsin(h))

cos(h)=1/(sqrt(1+tan^2(h)))

sin(h)=sqrt(tan^2(h)/(1+tan^2(h)))