Prévia do material em texto
Eduarda Leal de Carvalho Álgebra Linear Algorítmica DRE: 118199369 Marcelo G. Teixeira Laboratório 3 – Bolinha Refletida Seja Q um quadrado com os seguintes vértices: (a, b), (c, d), (e, f) e (g, h). Para transforma-lo em um paralelogramo, basta aplicar a matriz de cisalhamento nesses vértices: T(x, y) = (x + 𝜆y, y) ou [ 𝑥 𝑦] ↦ [ 𝜒 + 𝜆𝑦 𝑦 ] Obtemos os seguintes vértices: v1 = [ a b ] ↦ [ a + 𝜆b b ] v2 = [ c d ] ↦ [ c + 𝜆d d ] v3 = [ e f ] ↦ [ e + 𝜆f f ] v4 = [ g h ] ↦ [ g + 𝜆h h ] Logo a matriz do quadrado Q será: Q = [ a + 𝜆b b c + 𝜆d d e + 𝜆f f g + 𝜆g h ] Agora, para que a bolinha respeite esse novo domínio, é necessário fazer uma verificação. Para verificar se a bolinha encosta nas arestas do paralelogramo, é calculado a distancia perpendicular entre a bolinha e cada aresta. Para cada aresta é realizado os seguintes passos: Observação: Com intuito de apenas exemplificar os cálculos realizados, abaixo só consta os cálculos feitos para a aresta dos vértices 1 e 2. Os cálculos foram feitos para as demais arestas. 1. Calcular o vetor da aresta (𝒗𝒂) 𝑣1 = [ 𝑎 + 𝜆𝑏 𝑏 ] 𝑣2 = [ 𝑐 + 𝜆𝑑 𝑑 ] 𝑣𝑎 = [ 𝑥𝑣2 − 𝑥𝑣1 𝑦𝑣2 − 𝑦𝑣1 ] 𝑣𝑎 = [ 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 𝑑 − 𝑏 ] 2. Normalizar o vetor da aresta (𝑢) 𝑣𝑎 = [ 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 𝑑 − 𝑏 ] 𝑐𝑜𝑚𝑝𝑟𝑖𝑚𝑒𝑛𝑡𝑜 = √𝑥2 + 𝑦2 𝑑𝑝𝑎 = (𝑥𝑏 − 𝑐 − 𝜆𝑑 + 𝑎 + 𝜆𝑏) × 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 + (𝑦𝑏 − 𝑑 + 𝑏) × 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 𝑐𝑜𝑚𝑝𝑟𝑖𝑚𝑒𝑛𝑡𝑜 = √(c + 𝜆d - a - 𝜆b)2 + (𝑑 − 𝑏)2 𝑢 = [ 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2] 3. Calcular o vetor perpendicular (𝒗𝒑) 𝑣𝑝 = [ − 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 c + 𝜆d − a − 𝜆b √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 ] 4. Calcular o vetor da bolinha em relação ao primeiro vértice da aresta (𝒗𝒃) 𝑣𝑎 = [ 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 𝑑 − 𝑏 ] 𝑐𝑏 = [ 𝑥𝑏 𝑦𝑏 ] 𝑣𝑏 = [ 𝑥𝑏 − (c + 𝜆d - a - 𝜆b) 𝑦𝑏 − (𝑑 − 𝑏) ] 𝑣𝑏 = [ 𝑥𝑏 − 𝑐 − 𝜆𝑑 + 𝑎 + 𝜆𝑏 𝑦𝑏 − 𝑑 + 𝑏) ] 5. Calcular a distância perpendicular ( 𝒅𝒑) 𝑣𝑏 = [ 𝑥𝑏 − 𝑐 − 𝜆𝑑 + 𝑎 + 𝜆𝑏 𝑦𝑏 − 𝑑 + 𝑏) ] 𝑣𝑝 = [ − 𝑑 − 𝑏 √(c + 𝜆d − a − 𝜆b)2 + (𝑑 − 𝑏)2 c + 𝜆d − a − 𝜆b √(c + 𝜆d − a − 𝜆b)2 + (𝑏 − 𝑑)2 ] 𝑑𝑝 = (𝑥𝑏 − 𝑐 − 𝜆𝑑 + 𝑎 + 𝜆𝑏) × − 𝑑 − 𝑏 √(c + 𝜆d − a − 𝜆b)2 + (𝑑 − 𝑏)2 ) + (𝑦𝑏 − 𝑑 + 𝑏) × c + 𝜆d − a − 𝜆b √(c + 𝜆d − a − 𝜆b)2 + (𝑏 − 𝑑)2 6. Calcular a distância paralela (𝒅𝒑𝒂) 𝑣𝑟 = 2 × (𝑣𝑥 × − 𝑑 − 𝑏 √(c + 𝜆d − a − 𝜆b)2 + (𝑑 − 𝑏)2 ) + 𝑣𝑦 × c + 𝜆d − a − 𝜆b √(c + 𝜆d − a − 𝜆b)2 + (𝑏 − 𝑑)2 ) × [ − 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 c + 𝜆d − a − 𝜆b √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 ] 𝑣𝑏 = [ 𝑥𝑏 − 𝑐 − 𝜆𝑑 + 𝑎 + 𝜆𝑏 𝑦𝑏 − 𝑑 + 𝑏) ] 𝑢 = [ 𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2] Se a distância paralela for maior que 0 e o comprimento da aresta, e a distância perpendicular estiver dentro de uma tolerância, a bolinha está encostando na aresta e sua velocidade é refletida. Para refletir a bolinha ao colidir com uma aresta, foi feito o seguinte: 1. Para calcular o vetor de reflexão (𝑣𝑟), foi o produto escalar entre a velocidade da bolinha e o vetor perpendicular foi multiplicado por 2 e pelo vetor perpendicular. 𝑣𝑒𝑙𝑜𝑐𝑖𝑑𝑎𝑑𝑒 = (𝑣𝑥, 𝑣𝑦) 𝑣𝑝 = [ − 𝑑 − 𝑏 √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 c + 𝜆d − a − 𝜆b √(𝑐 + 𝜆𝑑 − 𝑎 − 𝜆𝑏)2 + (𝑑 − 𝑏)2 ] 𝑅 = 2 × (𝑣𝑥 × − 𝑑 − 𝑏 √(c + 𝜆d − a − 𝜆b)2 + (𝑑 − 𝑏)2 ) + 𝑣𝑦 × c + 𝜆d − a − 𝜆b √(c + 𝜆d − a − 𝜆b)2 + (𝑏 − 𝑑)2 ) 𝑣𝑟 = 𝑅 × 𝑣𝑝 2. Para achar a velocidade refletida foi subtraído o vetor de reflexão da velocidade da bolinha. 𝑣𝑟 = (𝑣𝑟𝑥 , 𝑣𝑟𝑦) 𝑣𝑒𝑙𝑜𝑐𝑖𝑑𝑎𝑑𝑒 = (𝑣𝑥, 𝑣𝑦) 𝑣𝑒𝑙𝑜𝑐𝑖𝑑𝑎𝑑𝑒𝑟𝑒𝑓𝑙𝑒𝑡𝑖𝑑𝑎 = (𝑣𝑥 − 𝑣𝑟𝑥 , 𝑣𝑦 − 𝑣𝑟𝑦)