Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void metodoAnalitico(float xInicial, float xFinal, float xProx, float yInicial, float yFinal, float yProx, float i, float coeficienteAngular)
- {
- puts("X Y");
- xProx = xInicial;
- yProx = yInicial;
- for (i = xInicial; i <= xFinal; i = i + 0.5)
- {
- printf("%f %f\n", xProx, yProx);
- xProx = xProx + 0.5;
- yProx = coeficienteAngular*(xProx) + yInicial;
- }
- }
- void metodoDDA(float difX, float difY, float xInicial, float xFinal, float xProx, float yInicial, float yFinal, float yProx, float i, float coeficienteAngular)
- {
- if(difX > difY)
- {
- yProx = yInicial;
- xProx = xInicial;
- for (i = xInicial; i <= xFinal; i++)
- {
- printf("%f %f\n", xProx, yProx);
- xProx = xProx++;
- yProx = coeficienteAngular + yProx;
- }
- }
- else if(difX < difY)
- {
- yProx = yInicial;
- xProx = xInicial;
- for (i = yInicial; i <= yFinal; i++)
- {
- printf("%f %f\n", xProx, yProx);
- yProx = yProx++;
- xProx = (1/coeficienteAngular) + xProx;
- }
- }
- }
- int main()
- {
- float xInicial, yInicial, xFinal, yFinal, coeficienteAngular, i, yProx, xProx, difX, difY;
- printf("X inicial: ");
- scanf("%f", &xInicial);
- printf("Y inicial: ");
- scanf("%f", &yInicial);
- printf("X final: ");
- scanf("%f", &xFinal);
- printf("Y final: ");
- scanf("%f", &yFinal);
- coeficienteAngular = (yFinal - yInicial)/(xFinal - xInicial);
- difX = xFinal - xInicial;
- difY = yFinal - yInicial;
- puts("\n\nMETODO ANALITICO");
- printf("Coef. Angular: %f\n", coeficienteAngular);
- metodoAnalitico(xInicial, xFinal, xProx, yInicial, yFinal, yProx, i, coeficienteAngular);
- puts("\n\nMETODO DDA");
- printf("Coef. Angular: %f\n", coeficienteAngular);
- metodoDDA(difX, difY, xInicial, xFinal, xProx, yInicial, yFinal, yProx, i, coeficienteAngular);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement