Does anyone have an example of code working with half-planes? In particular, by the equation of the straight line ax + by + c = 0 , which defines a half-plane in which ax + by + c> = 0 is unique. I just need a way to do this, my work just got confused, I processed all possible slopes of the straight line (or rather, the ranges), and there was a terrible amount of code.

Or if it's easier then help with this task - https://www.e-olymp.com/ru/problems/2960 . (Conceptually, I perfectly understand what they want from me). I wrote a preschool account, but when it comes to working with the most direct, and how to understand which half-plane in me is processed purely at the implementation level, I cannot think of it. It is sure, there some very short and simple code, but not those 12 if-s, with enclosures which I made. Once again, I do not ask for me to solve it, I want to see an example of implementation, because I myself do not have enough sense to do it, only for a complete analysis of cases. (I understand the code in js, c #, c ++, python, php)

  • Comments are not intended for extended discussion; conversation moved to chat . - Yuriy SPb

1 answer 1

The -Sign(c) * (ax+by+c) < 0 as -Sign(c) * (ax+by+c) < 0 - the value of the expression -Sign(c) * (ax+by+c) < 0 negative for those points that are on the same side of a line with the origin (0, 0) , and positive for points located on opposite sides from the line with the origin. (It is easier to reduce the equation of a line to a form with a negative c)

Example: line y=2x+1 or 2x-y+1=0 . Point (1,10) higher than the line, and the origin is lower, the expression, taking into account the sign of c gives a positive result

  • The value of the expression ax+by+c positive for those points that lie on the same side of the line to which the normal vector (a, b) points. - AnT
  • @AnT And to find out if this is the side, you can do a cross-product with a vector or a dot-product with a normal, as a result, the expression will be the same. And the direction of the normal vector (of which there are two) depends on the sign of c, which is taken into account in the formula - MBo