GMK

Need math help

7 posts in this topic

Let's say I have a font size at any given pixels.  In a certain program, the auto-sized box given this font size has a height that can be calculated using the following formula:

Global $iPixels = 100
Global $iBoxHeight = $iPixels + Int($iPixels / 5) + 14 ; $iBoxHeight = 134

I can't for the life of me figure out how to find the pixels, given the height, or if it's even possible.

Any help would be greatly appreciated.  Thanks!

Share this post


Link to post
Share on other sites



Can you test this:

$iPixels = Round(($iBoxHeight - 14) * 5 / 6)

 


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

It's close, but not exact.

#include <Array.au3>
Global Enum $ePx, $eBoxHeight, $ePxCalculated
Global $aArray[100][3]
For $iRow = 0 To 99
    $aArray[$iRow][$ePx] = $iRow + 1
    $aArray[$iRow][$eBoxHeight] = $aArray[$iRow][$ePx] + Int($aArray[$iRow][$ePx] / 5) + 14
    $aArray[$iRow][$ePxCalculated] = Round(($aArray[$iRow][$eBoxHeight] + 1 - 14) * 5 / 6)
Next
_ArrayDisplay($aArray)

 

Share this post


Link to post
Share on other sites

Thank you, by the way.

Share this post


Link to post
Share on other sites

I found some help here.

$iPixels = Ceiling(($iBoxHeight * 5 - 70) / 6)

Thanks, @jchd!

Share this post


Link to post
Share on other sites

Yup, I wasn't sure about the rounding direction. Both equation yield the same result before rounding (ceil vs. floor).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

If my algebra still works,

$iBoxHeight = $iPixels + Int($iPixels / 5) + 14

I translate to

H = P + (P/5) + 14
H-14 = P + (P/5)
H-14 = 1.2P
(H-14)/ 1.2 = P

or in your variables, = ($iHeight - 14) / 1.2 = $iPixels

Substituting the numbers, 
(134-14)/1.2 = $iPixels  ; (Height-14) / 1.2 = Pixels
120/1.2 = $iPixels
100 = $iPixels

Use  (Height-14) / 1.2 = Pixels

That's the math.  You can work on rounding to whole numbers if necessary.  Hope you can follow that.  Hope I didn't make a mistake; it's been a long time., but I think that's right.

Good luck,

_aleph_

Edited by aleph01
spelling correction

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now