Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this funciton for interpolation max , i need to creat the same funciton for min .
thank you in advance

What I have tried:

float fInterpol2(float x, float x1, float y1, float x2, float y2) //interpolation function getMaxPowerPriority
{
	// x = input from the sensor
	// x1, x2 = boundary condition of the sensor input.
	// y1, y2 = boundary condition of the desired output.
	float y; // desired output.
	
	y = (((y2 - y1) / (x2 - x1)) * (x - x1)) + y1;	

	if(y > y1) y = y1;
	if(y < y2) y = y2;
	
	return y;
}
Posted
Comments
CPallini 15-Mar-18 4:42am    
What do you mean with 'interpolation max' and 'interpolation min'?
The above formula is linear interpolation.
BaselAla 15-Mar-18 4:49am    
right , but by this function i get the Ymax , how i can get Ymin??
thank you for your answer
CPallini 15-Mar-18 6:19am    
Nope. That function simply scales the (x1,x2) to the (y1,y2) range. You should get ymin (that is y1) when x <= x1; on the other hand, you should get ymax (that is y2) when x>=x2.
By the way, I believe the boundary checks are wrong. They should be instead
if ( y > y2 ) y = y2;
if ( y < y1 ) y = y1;
BaselAla 15-Mar-18 10:00am    
i thank you very much
CPallini 15-Mar-18 11:42am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900