Mathematics Have Got Me Crying

Hey everyone, I got a new one.

I am writing a simple program to help determine which lens one would get for a specific camera. The proccess seems simple enough, but I keep getting nowhere.

I have a series of Radio Buttons depicting which type of camera mount you have, there are four options and depending on which one you choose it sets a value for two variables.

I then have a text box where you enter the Lens Size and another where you enter the distance. These are both stored as independant variables.

The calulations are pretty simple, you take the Distance and multimply it by the value set with the radio button selection, you the divide that by the Lens Size. The whole thing sounds very easy, and I'm probably missing something very stupid and easy, but if someone sees it please help me, this is driving me crazy.

Here's my code so far:

Public Class Calclator
Dim Lens As Decimal
Dim VCamera As Decimal
Dim HCamera As Decimal
Dim Distance As Decimal
Dim VFOV As Decimal
Dim HFOV As Decimal

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Lens = Val(txtLensSize.Text)
Distance = Val(txtDistance.Text)
If rbn14.Checked Then
VCamera = 2.7 And HCamera = 3.6
ElseIf rbn13.Checked Then
VCamera = 3.6 And HCamera = 4.8
ElseIf rbn12.Checked Then
VCamera = 4.8 And HCamera = 6.4
ElseIf rbn23.Checked Then
VCamera = 6.6 And HCamera = 8.8
End If

VFOV = Distance * VCamera / Lens
txtVFOV.Text = VFOV
HFOV = Distance * HCamera / Lens
txtHFOV.Text = HFOV
End Sub
End Class
[1738 byte] By [CameronHoy] at [2008-1-10]
# 1

Hi

Well, you are writing in english with two statements on one line joined by "and". The computer don?t understan all the "and's" you are using. So remove all the and's between VCamera and HCamera and split the statements on two lines like:

VCamera = 2.7

HCamera = 3.6

Regards

Csaba

CsabaU at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
Oh thank you so much, that was so simple, I thought my math was wrong somewhere. One more question, I have no idea how I would write this out in code:

2Tan^-1 * VCamera / 2Lens.

The best I could come up with is this:

(2 * math.tan^-1) * (VCamera / (2 * Lens))

But when I use this I get the error code Error " Argument not specified for parameter 'a' of 'Public Shared Function Tan(a As Double) As Double"

Any help would be greatly appriciated.

CameronHoy at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Hi again,

This is a little embarrising, it is 18 year ago I worked woth all those functions, so it is litle unclear for me.

Tan^-1, isn't it really arctan? Then 2Tan^-1 * VCamera / 2Lens should first be rewritten as 2arctan(VCamera / 2Lens.)?

And then implemented as 2 * Math.Atan(VCamera / (2 * Lens))?

I assume it is not 2*Math.tan(VCamera / (2 * Lens) )^-1 = 2/Math.tan(VCamera / (2 * Lens) ) you want

(Anyhow, it is the expression within () to Math.Tan alternatively Math.Atan that the complier is missing)


Regards

Csaba

CsabaU at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

Hi,

It might be.>>

Dim result As Decimal

result = Math.Atan(2) * (VCamera / (2 * Lens))

Regards,

John

JohnOliver(UK)MSP,VSIP at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
You guys are geniuses, that worked perfectly. Although somewhere in the line the math is wrong, because I'm getting the wrong answer lol. Thank you both very much for your help.
CameronHoy at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6
I think I figured out why the math is wrong again, i think I'm supposed to actually be taking the Arctangent of the variables. The equation I'm trying to code out looks like this:

VAOV = 2 Atan (VCamera / 2Lens)

I have this coded like this:

VAOV = 2 * math.Atan(VCamera / (2 * Lens))

You would think this is right, but with a VCamera of 2.7 and a Lens of 20, the answer should be 7.5 and I keeo getting 0.134795527436479. I'm quite lost, so if there are any math geniuses out there, I could use you.

CameronHoy at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 7

Well, what units where? As I said, it was long time ago:

Maybe only you get the naser in radians and want it in degree? - > 0.134795527436479*180/3.14 =7.72 ?

Regards

Csaba

CsabaU at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 8
Amazing! That is it for sure, I really Really appriciate your help, you have saved this project for me.
CameronHoy at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 9

Hi,

All the TRIGonomertry functions in VB.Net work in Radians not degrees.

If you are wondering where the (180 / 3.14) comes from

360 degrees = 2* Pi radians.

So 180 degrees = Pi Radians = 3.1415926535897932384626433832795 radians.

Radians are a measure of the curved outer line of a circle as an angle

or a portion of a circle ( or an arc ) as an angle in relation to the circle centre.

An eighth of a circle is 360 / 8 = 45 degrees.

In radians this is ( 2 * Pi ) / 8 = 0.78539816339744830961566084581988 radians.

I hope this makes radians clearer.

>>

Code Snippet

Public Class Form1

'The next highlighted line should be one line of code in your window.>>>>

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim result As Double = 0

'2 * Pi radians = 360 degrees.

result = 0.134795527436479 * (360 / (2 * Math.PI))

'Round to 2 decimal places.

result = Math.Round(result, 2)

MessageBox.Show(result.ToString)

End Sub

End Class

Regards,

John

JohnOliver(UK)MSP,VSIP at 2007-10-3 > top of Msdn Tech,Visual Basic,Visual Basic General...