Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: Clyde on February 08, 2007

Title: What is meant by Interpolate?
Post by: Clyde on February 08, 2007
I'm going to be making a draw triangle routine. So far I've discovered that you can either have; flat bottom, flat top or a generic triangle ( which is basically 2 triangles, one a flat top the other a flat bottom ). And have been looking at a few examples, and have noticed Interpolate crop up alot and wondered what was meant by it?

Cheers and many thanks,
Clyde.

Title: Re: What is meant by Interpolate?
Post by: Shockwave on February 08, 2007
To interpolate means to move between two values over a given time / distance.

For example, if you have two sets of co-ordinates;

X1=100
Y1=100

X2=150
Y2=200

You could say;

Inter = (X2 - X1) / (Y2 - Y1)

For a=Y1 to Y2

Xcurrent =Xcurrent + inter

next

That is the sort of thing you will be doing in your triangle routine.
Basically you work out the distance of X and then divide it by the amount of steps you are going to do which will give you a value that you can add or subtract to get you where you want to go.

You need this technique for lots of stuff, it's worth learning.
Title: Re: What is meant by Interpolate?
Post by: Clyde on February 08, 2007
Cheers mate, so I would first need to work out what is biggest and smallest values were for calculating interpolations?
Title: Re: What is meant by Interpolate?
Post by: rain_storm on February 08, 2007
Bresenham's line drawing algorithm is one of the best examples (real fast) and can be easily adapted to triangles and even curves its accurate to one pixel and where the line is +.5 the value will round up
Title: Re: What is meant by Interpolate?
Post by: Shockwave on February 08, 2007
Clyde, what you need to interpolate between two values are;

Value 1
Value 2

Amount of steps

You subtract one value from the other and divide by the number of steps.
Once you have the step to add in the loop it's fairly easy to say for example;

current_number = current_number + step size

at it's most simple, a for next loop uses interpolation.

For A = 0 to 100 step 10
Print A
next A

Interpolation is just a large word which means to go from one number to a target number.

You don't need to swap the numbers around generally. (ie smallest and largest).
This is because if the result of x1-x2 is negative or positive, it won't matter.

If STEP is -1.1 and Current = 0

current=current + STEP

Current would now be -1.1

If STEP is +1.1 and Current = 0

current=current + STEP

Current would now be +1.1

So it all comes out right.
Make sure that you use signed numbers, singles or doubles where you can.