|
-
Oct 1st, 2009, 10:53 AM
#1
[RESOLVED] convert pixels² to cm²
i've got a formula for calculating the area of a triangle:
vb Code:
x1 = points(1).X
y1 = points(1).Y
x2 = points(2).X
y2 = points(2).Y
x3 = points(0).X
y3 = points(0).Y
Dim area As Decimal = (0.5 * ((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))))
Debug.Print(unitConverter.pixelsSquaredToCMSquared(gr, area))
it works well but it calculates the output in pixels² + i need it to be cm²
heres my converter function that works well converting a pixel length to a cm length, but doesn't work with pixels²:
vb Code:
Public Shared Function pixelsSquaredToCMSquared(ByVal gr As Graphics, ByVal pixels As Decimal) As Decimal
Return (pixels / gr.DpiX) * 2.54
End Function
what am i doing wrong?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 1st, 2009, 09:44 PM
#2
Re: convert pixels² to cm²
If 100 pixels are 5 cm's [for instance], then 100*100 pixels^2 are 5*5 cm^2. That is, the conversion factor needs to get squared too.
Example:
Say there's 20 pixels to a cm. Convert 800 pixels^2 to some number of cm^2. Ok... since 800 = 20*40, we see
800 pixels^2 = 20 pixels * 40 pixels = 1 cm * 2 cm = 2 cm^2.
In general, if we have X pixels to 1 cm, and we want to convert A pixels^2 to cm^2, we use...
A pixels^2 = (A / (X^2)) cm^2
The formula you seem to be using is A pixels^2 = (A / X) cm^2, which will give you confusingly wrong results.
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 2nd, 2009, 06:03 AM
#3
Re: convert pixels² to cm²
To be more explicit, the following should do what you want:
vb Code:
Public Shared Function pixelsSquaredToCMSquared(ByVal gr As Graphics, ByVal pixels As Decimal) As Decimal
Return pixels * (2.54 / gr.DpiX) ^ 2
End Function
The time you enjoy wasting is not wasted time.
Bertrand Russell
<- Remember to rate posts you find helpful.
-
Oct 2nd, 2009, 10:34 AM
#4
Re: convert pixels² to cm²
thanks jemediah, that worked.
saved a lot of head scratching rated+
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|