KUVAUS |
Tarkistaa onko piste kolmion sisällä ja palauttaa True (1) jos näin on, muutoin False (0). |
KÄYTTÖ |
PointInTriangle(x, y, x1, y1, x2, y2, x3, y3) |
x, y = Kokeiltavan pisteen koordinaatit x1, y1 = Kolmion ensimmäisen kärkipisteen koordinaatit x2, y2 = Kolmion toisen kärkipisteen koordinaatit x3, y3 = Kolmion kolmannen kärkipisteen koordinaatit |
Katso myös: TriangleArea
ESIMERKKI |
Include "sdk/include/cbMath.cb" // Arvotaan kolmio x1 = Rand(0, ScreenWidth()) y1 = Rand(0, ScreenHeight()) x2 = Rand(0, ScreenWidth()) y2 = Rand(0, ScreenHeight()) x3 = Rand(0, ScreenWidth()) y3 = Rand(0, ScreenHeight()) Repeat x = MouseX() y = MouseY() If MouseHit(1) Then // Mahdollisuus muuttaa kolmion pisteiden paikkoja If KeyDown(cbKey1) Then x1 = x: y1 = y If KeyDown(cbKey2) Then x2 = x: y2 = y If KeyDown(cbKey3) Then x3 = x: y3 = y EndIf Color 255, 255, 255 // Muuta väriä jos hiiri on kolmion sisällä If PointInTriangle(x, y, x1, y1, x2, y2, x3, y3) = True Then Color 255, 0, 0 Line x1, y1, x2, y2 Line x2, y2, x3, y3 Line x3, y3, x1, y1 DrawScreen Forever |