Last active
April 7, 2024 12:33
-
-
Save hilios/4214c96d0dfbaf932434 to your computer and use it in GitHub Desktop.
Instituto Mauá de Tecnologia - Trabalho prático I (http://bit.ly/1D8yncN)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""1) Construa um algoritmo que, tendo como dados de entrada dois | |
pontos quaisquer no plano, P(x1,y1) e P(x2,y2), escreva a distância | |
entre eles. A fórmula que efetua tal cálculo: | |
d = sqrt(Δx^2 + Δy^2) | |
""" | |
import lib | |
import math | |
def distancia(p1, p2): | |
dx = p1[0] - p2[0] | |
dy = p1[1] - p2[0] | |
return math.sqrt(dx ** 2 + dy ** 2) | |
print 'Digite os pontos:' | |
p1 = point_input() | |
p2 = point_input() | |
print 'A distancia entre eles é', distancia(p1, p2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""2) Utilizando a função de cálculo de distância entre dois pontos do | |
execício anterior, escreva uma função que receba uma lista de pontos | |
P(xi, yi) e retorne a maior distância entre eles. | |
""" | |
import lib | |
import math | |
def maior_distancia(pontos): | |
md = 0 | |
for i in pontos: | |
for j in pontos: | |
d = distancia(i, j) | |
if d > md: | |
md = d | |
return md | |
print 'Digite os pontos:' | |
pontos = collect_points() | |
print 'A maior distancia nessa lista é:', maior_distancia(pontos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""3) Construa um algoritmo que, tendo como dados de entrada dois | |
pontos cartesianos quaisquer no plano, P(x1,y1) e P(x2,y2), escreva-os | |
como coordenadas polares. | |
""" | |
import lib | |
import math | |
def coord_polar(p1, p2): | |
dx = p1[0] - p2[0] | |
dy = p1[1] - p2[0] | |
return (distancia(p1, p2), math.degrees(math.atan2(dy, dx))) | |
print 'Digite os pontos:' | |
p1 = point_input() | |
p2 = point_input() | |
print coord_polar(p1, p2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""4) Elaborar um algoritmo que lê 3 valores A, B, C e verificar se | |
eles formam ou não um triângulo retângulo. Suponha que os valores lidos | |
são inteiros e positivos. | |
a. Caso os valores formem um triângulo, calcular e escrever a área | |
deste triângulo. | |
b. Se não formam triângulo escrever os valores lidos. | |
Dica: A hipotenusa é maior que os catetos, porém, menor que a soma deles. | |
""" | |
import lib | |
import math | |
print 'Digite os perimetros do triângul:' | |
def testa_triangulo_restangulo(a, b, c): | |
hiptenusa = max(a, b, c) | |
cateto1 = min(a, b, c) | |
cateto2 = sum([a, b, c]) - hiptenusa - cateto1 | |
if hiptenusa < cateto1 + cateto2: | |
area = (cateto1 * cateto2) /2 | |
print 'Os valores (%f, %f, %f) formam um ' % (a, b, c) + \ | |
'triângulo retângulo com área %f' % area | |
else: | |
print 'Os valores (%f, %f, %f) não formam um ' % (a, b, c) + \ | |
'triângulo retângulo' | |
a, b, c = point_input_3d() | |
testa_triangulo_restangulo(a, b, c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""5) Os satélites do sistema de posicionamento GPS por padrão enviam a | |
localização de um ponto gográfico em coordenadas cartesianas (x,y,z). | |
Escreva um algoritmo que receba como entrada as coordenadas cartesianas | |
e transforme-as em coordenadas geográficas latitude (ϕ), longitude (λ) | |
como graus decimais e altitude (h). | |
A fórmula que calcula a longitude é: | |
tan(λ) = Y / X | |
Para a latitude, faz necessário realizar uma iteração de f(ϕ): | |
tan(ϕ) = Z/P * (1-E * N / (N+h)) ^ -1 | |
Em uma primeira aproximação, faz-se h = 0 e N = 1. Com esses valores | |
obtem-se f(ϕ) e recalcula-se um novo h e N, então aplicamos os novos | |
valores em f(ϕ) e assim sucessivamente (5 interações são o | |
suficiente). Tal que: | |
P = sqrt(X^2 + Y^2) | |
N = a / sqrt(1-E sen^2(ϕ)) | |
h = (P / cos(ϕ)) -N | |
Assuma o raio da terra sendo a = 6.378.160 km e o achatamento como | |
E^2 = 0,00669454185. No Python as funções seno, cosseno, tangente e | |
inversas trabalham em radianos. | |
""" | |
import lib | |
import math | |
# World Datum | |
A = 6378160 | |
E2 = 0.00669454185 | |
def cart2geo(x, y, z, precision=5): | |
P = math.sqrt(x ** 2 + y ** 2) | |
N = 1 | |
h = 0 | |
lng = math.atan2(y, x) | |
# print "lng = %f" % lng | |
for i in range(precision): | |
lat = math.atan(z / (P * (1 - E2 * N / (N + h)))) | |
# print "lat = %f, N = %f, h = %f" % (lat, N, h) | |
N = A / math.sqrt(1 - E2 * math.sin(lat) ** 2) | |
h = P / math.cos(lat) - N | |
return math.degrees(lat), math.degrees(lng), h | |
print 'Digita coordenadas cartesianas:' | |
# 4010210.546, -4260166.288, -2533008.133 | |
x, y, z = point_input_3d() | |
print cart2geo(x, y, z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def point_input(): | |
p = raw_input('Digite um ponto P(x,y): ').split(',') | |
return (float(p[0]), float(p[1])) | |
def point_input_3d(): | |
p = raw_input('Digite um ponto P(x,y,z): ').split(',') | |
return (float(p[0]), float(p[1]), float(p[2])) | |
def collect_points(fn=point_input): | |
p = [] | |
insert = True | |
while insert: | |
p.append(fn()) | |
insert = raw_input('Quer inserir outro ponto? [s/N]: ') | |
insert = insert[:1].lower() == 's' | |
return p |
qual linguagem v c usou?
Python
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
qual linguagem v c usou?