Skip to content

Commit

Permalink
Create main.c
Browse files Browse the repository at this point in the history
  • Loading branch information
danuaemx authored Nov 13, 2024
1 parent 0ae3ab8 commit 5e01d99
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions robotica/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <math.h>

#define L1 10.0
#define L2 8.0
#define RAD_DEG (180/M_PI)

void calcular_natural(double x, double y, double *m_Hip, double *phi){
double l3 = sqrt(pow(x, 2) + pow(y, 2));
double theta = atan2(y, x);
double cos_Phi = (pow(l3, 2) - pow(L1, 2) - pow(L2, 2)) / (2 * L1 * L2);
*phi = acos(cos_Phi);
double sin_Phi = sin(*phi);
double zeta = atan2(L2 * sin_Phi, L1 + L2 * cos_Phi);
*m_Hip = 180 + (theta - zeta) * RAD_DEG;
*phi *= RAD_DEG;
}
void calcular_adicional(double x, double y, double *m_Hip, double *phi){
double l3 = sqrt(pow(x, 2) + pow(y, 2));
double theta = atan2(y, x);
double cos_Phi = (pow(l3, 2) - pow(L1, 2) - pow(L2, 2)) / (2 * L1 * L2);
*phi = acos(cos_Phi);
double sin_Phi = sin(*phi);
double zeta = atan2(L2 * sin_Phi, L1 + L2 * cos_Phi);
//Cambiar formulas para segunda solución
*m_Hip = 180 + (theta + zeta) * RAD_DEG;
*phi *= -1*RAD_DEG;
}

int main(){
double x, y;
double qhip, qknee;
double qhip_1, qknee_1;

// Solicitar las coordenadas X e Y
printf("Introduce la coordenada X: ");
scanf("%lf", &x);

printf("Introduce la coordenada Y: ");
scanf("%lf", &y);

// Calcular los ángulos de la cadera y la rodilla
calcular_natural(x, y, &qhip, &qknee);
calcular_adicional(x,y,&qhip_1, &qknee_1);

// Imprimir los resultados
printf("El ángulo de la cadera (qHip) es: %.2f grados a partir de Rot(z,180)\n", qhip);
printf("El ángulo de la rodilla (qKnee) es: %.2f grados\n", qknee);
printf("El ángulo de la cadera extra (qHip) es: %.2f grados a partir de Rot(z,180)\n", qhip_1);
printf("El ángulo de la rodilla extra (qKnee) es: %.2f grados\n", qknee_1);

return 0;
}

0 comments on commit 5e01d99

Please sign in to comment.