Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

최다인/BilinearInterpolation: Difference between revisions

From ZeroWiki
imported>miura0806
No edit summary
No edit summary
 
Line 1: Line 1:
* 2014년 4월 3일 개발
DeleteThisPage
* 문제 : http://cau.ac.kr/~bongbong/c12/ -> Homework #4 -> Prob2. [[Bilinear Interpolation]]
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)
int computePosition(float, float);
float bilinearInterpolation(float*, float, float, int);
int main()
{
float xValue, yValue, a, b;
float pointValue[25];
int i, position;
printf("two float values x and y (ex: 0.5 1.0) : ");
scanf("%f %f",&xValue,&yValue);
printf("25 float values for the values at 25 grid points (ex: 1.0 3.5 ...)\n: ");
for(i = 0; i < 25; i++)
scanf("%f",&pointValue[i]);
position = computePosition(xValue, yValue);
a = xValue - (int)xValue;
b = yValue - (int)yValue;
printf("The Value at the coordinate (x,y) is %.3f\n",bilinearInterpolation(pointValue, a, b, position));
system("pause");
return 0;
}
int computePosition(float xValue, float yValue)
{
int xposition = (int)xValue + 5*(int)yValue;
if(xposition%5 == 4)
xposition--;
if(xposition>=20)
xposition-=5;
return xposition;
}
float bilinearInterpolation(float pointValue[25],float a, float b, int position)
{
float f12, f34;
f12 = a*pointValue[position+1] + (1-a)*pointValue[position];
f34 = a*pointValue[position+6] + (1-a)*pointValue[position+5];
return b*f34 + (1-b)*f12;
}
-----
[[최다인]]



Latest revision as of 03:16, 26 March 2017

DeleteThisPage