Created
June 6, 2013 01:50
-
-
Save arthurxavierx/5718749 to your computer and use it in GitHub Desktop.
Lista de exercícios 8 - Registros
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
typedef struct PONTO { | |
float x, y; | |
} PONTO; | |
void atribuiValorPonto(PONTO* p, float a, float b) { | |
p->x = a; | |
p->y = b; | |
} | |
float dist(PONTO* p1, PONTO* p2) { | |
return sqrt(pow(p1.x - p2.x, 2) - pow(p1.y - p2.y, 2)); | |
} | |
// -------------------------------------------------------- | |
typedef struct TRIANGULO { | |
PONTO p[3]; | |
} TRIANGULO; | |
float perimetro_triangulo(TRIANGULO* t) { | |
ushort i; | |
float p = 0.0f; | |
for(i = 0; i < 2; i++) | |
p += dist(t->p[i+1], t->p[i]); | |
return p; | |
} | |
float area_triangulo(TRIANGULO* t) { | |
return 0.5f*absf((t->p[0].x - t->p[2].x)*(t->p[1].y - t->p[0].y) - (t->p[0].x - t->p[1].x)*(t->p[2].y - t->p[0].y)); | |
} | |
int triangulo_equilatero(TRIANGULO* t) { | |
return (dist(t->p[0], t->p[1]) == dist(t->p[1], t->p[2])) && (dist(t->p[1], t->p[2]) == dist(t->p[2], t->p[0])); | |
// -------------------------------------------------------- | |
typedef struct CIRCUNFERENCIA { | |
PONTO* p; | |
float r; | |
} CIRCUNFERENCIA; | |
float perimetro_circunferencia(CIRCUNFERENCIA* c) { | |
return 2*M_PI*c->r; | |
} | |
float area_circunferencia(CIRCUNFERENCIA* c) { | |
return M_PI*c->r*c->r; | |
} | |
int intersecao_circunferencia(CIRCUNFERENCIA* c, PONTO* p) { | |
return dist(p, c->p) < c->r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment