Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.98 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. void metodoAnalitico(float xInicial, float xFinal, float xProx, float yInicial, float yFinal, float yProx, float i, float coeficienteAngular)
  4. {
  5.     puts("X         Y");
  6.     xProx = xInicial;
  7.     yProx = yInicial;
  8.     for (i = xInicial; i <= xFinal; i = i + 0.5)
  9.     {
  10.         printf("%f  %f\n", xProx, yProx);
  11.         xProx = xProx + 0.5;
  12.         yProx = coeficienteAngular*(xProx) + yInicial;
  13.     }
  14. }
  15.  
  16. void metodoDDA(float difX, float difY, float xInicial, float xFinal, float xProx, float yInicial, float yFinal, float yProx, float i, float coeficienteAngular)
  17. {
  18.     if(difX > difY)
  19.     {
  20.         yProx = yInicial;
  21.         xProx = xInicial;
  22.         for (i = xInicial; i <= xFinal; i++)
  23.         {
  24.             printf("%f  %f\n", xProx, yProx);
  25.             xProx = xProx++;
  26.             yProx = coeficienteAngular + yProx;
  27.         }
  28.     }
  29.     else if(difX < difY)
  30.     {
  31.         yProx = yInicial;
  32.         xProx = xInicial;
  33.         for (i = yInicial; i <= yFinal; i++)
  34.         {
  35.             printf("%f  %f\n", xProx, yProx);
  36.             yProx = yProx++;
  37.             xProx = (1/coeficienteAngular) + xProx;
  38.         }
  39.     }
  40. }
  41.  
  42. int main()
  43. {
  44.     float xInicial, yInicial, xFinal, yFinal, coeficienteAngular, i, yProx, xProx, difX, difY;
  45.  
  46.     printf("X inicial: ");
  47.     scanf("%f", &xInicial);
  48.     printf("Y inicial: ");
  49.     scanf("%f", &yInicial);
  50.  
  51.     printf("X final: ");
  52.     scanf("%f", &xFinal);
  53.     printf("Y final: ");
  54.     scanf("%f", &yFinal);
  55.  
  56.     coeficienteAngular = (yFinal - yInicial)/(xFinal - xInicial);
  57.  
  58.     difX = xFinal - xInicial;
  59.     difY = yFinal - yInicial;
  60.  
  61.     puts("\n\nMETODO ANALITICO");
  62.     printf("Coef. Angular: %f\n", coeficienteAngular);
  63.     metodoAnalitico(xInicial, xFinal, xProx, yInicial, yFinal, yProx, i, coeficienteAngular);
  64.  
  65.     puts("\n\nMETODO DDA");
  66.     printf("Coef. Angular: %f\n", coeficienteAngular);
  67.     metodoDDA(difX, difY, xInicial, xFinal, xProx, yInicial, yFinal, yProx, i, coeficienteAngular);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement