Segments can be horizontal or vertical. I have the top point of the segment (if it is vertical) and left (if it is horizontal) and the length of the segment. How to find the shortest distance between them?

Segments (their number is 2) can be arranged as you like: both vertical; both horizontal; one horizontal, the other vertical; may intersect; may not intersect. Example of input data: 1) Horizontal, x = 100, y = 100, l = 50, 2) Vertical, x = 50, y = 250, l = 150;

  • Not at all clear: you have two segments, one of which is horizontal and the other is vertical? Or the data is simply two segments, but you do not know what they are? Show the input data specifically. - Adam
  • > between them. So you have two pieces? - VladD
  • 2
    Find the projections of the segments on the coordinate axes. Each segment will give a projection in the form of a point on one axis and in the form of a segment on another. If the projections can overlap only along one axis, along both or not overlap, this will give information about the shortest distance (Pythagoras helps in the latter case). This is the logic. Any task begins with an analysis. - paulgri

0