Hi there

My brain's not working right either that early, but I try hard... ;-)

Value:= (X - crect.Left) / (crect.Right - crect.Left) * (Max-Min)+Min;

That should do the job.

Have fun
Armin

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Richard R
> Sent: Tuesday, September 13, 2005 5:14 PM
> To: 'Delphi-Talk Discussion List'
> Subject: a math problem
> 
> 
> Hello, I created a custom control called TtsxColorPanel. This 
> control sets a floating point value within a range from Min to 
> Max by where you click within the range of the control. It works 
> assuming that Min is 0, however I'm trying to make it work where 
> Min is any real number, but I am justnot seeing how I can add Min 
> into the following equation:
> 
> X is the X value of where the mouse is, and crect is the 
> control's coordinates. Max can be any real number.
> 
> Value:= (X - crect.Left) / (crect.Right - crect.Left) * Max;
> 
> This works perfectly as I mentioned, if Min is 0, but now I need 
> to add the Min variable into this and I have tried many 
> combinations but I cannot get it to work correctly. Any 
> suggestions? The first 2 parts of the equation calculates the 
> ratio of where the mouse is in relation to the width of the 
> rectangle area. If I add (Max - Min) then it just calculates it 
> wrong, making the value go above the max if my mouse is beyond 
> the middle point. Maybe this is a easy equation to fix, but my 
> brain isnt working this morning =P
> __________________________________________________
> Delphi-Talk mailing list -> [email protected]
> http://www.elists.org/mailman/listinfo/delphi-talk
> 
> 
> 


__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to