geometrylibgosu

how to find the coordinates of a triangle for the roof?


I want to put that blue triangle that is in the picture on my red house. i keep putting random number but i can not get it right. the problem is in the Gosu.draw_triangle section. people said this website will help https://www.rubydoc.info/github/gosu/gosu/master/Gosu.draw_triangle but i didn't get anything good out of it.

Picture

def initialize 
 def initialize
    super(800, 600, false)
  end

  def draw
    Gosu.draw_rect(310, 300, 200, 150, Gosu::Color::RED, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(385, 380, 50, 70, Gosu::Color::BLUE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(460, 335, 35, 35, Gosu::Color::BLUE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(0, 450, 1000, 400, Gosu::Color::GREEN, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(200, 100, 100, 45, Gosu::Color::WHITE, ZOrder::TOP, mode=:default)
    Gosu.draw_rect(100 , 350, 45, 120, 0xff_AC5B13 , ZOrder::TOP, mode=:default)
    Gosu.draw_triangle(20, 30, Gosu::Color::BLUE, 440, 230,  Gosu::Color::BLUE, 50, 345,  Gosu::Color::BLUE, ZOrder::TOP, mode=:default)

Solution

  • To place blue triangle on house top, you need to make Y-coordinates the same as rectangle top for two vertices of triangle.

    Needed rectangle vertices : ToplLeft, TopRight

    Triangle vertices:

    X1 = ToplLeft.X - OverhangSize
    Y1 = ToplLeft.Y
    X2 = ToplRight.X + OverhangSize
    Y2 = ToplLeft.Y
    X3 = (ToplLeft.X + ToplRight.X) / 2    //average vor symmetric roof
    Y3 = ToplLeft.Y - RoofHeight