Knowing two points of a rectangle, how can I figure out the other two?

前端 未结 9 1174
刺人心
刺人心 2021-01-05 01:47

Hey there guys, I\'m learning processing.js, and I\'ve come across a mathematical problem, which I can\'t seem to solve with my limited geometry and trigonometry knowledge o

9条回答
  •  [愿得一人]
    2021-01-05 01:59

    If you know the midpoint for the top, and the length of the top, then you know that the y will stay the same for both top corners, and the x will be the midpoint plus/minus the width of the rectangle. This will also be true for the bottom.

    Once you have the four corners, there is no need to worry about the side lengths, as their points are the same as those used for the top and bottom.

                             midpoint
         x,10                 10,10                   x,10
          *--------------------------------------------*
                             width = 30
    
        mx = midpoint x.
        top left corner = (w/2) - mx  or 15 - 10
        top left corner coords = -5,10
    
        mx = midpoint x.
        top right corner = (w/2) + mx  or 15 + 10
        top left corner coords = 25,10
    

提交回复
热议问题