|
-
Aug 7th, 2002, 08:29 AM
#1
Thread Starter
New Member
Accuracy of VB calculations (again...)
I need to calculate the angle subtended between the start and end point of a spiral and the entry tangent of the spiral. The spiral starts as a straight line and ends with a known radius.
As an example, you can use a spiral with a length of 156.025, and a spiral parameter of 395 (the radius can be calculated: Radius = Parameter^2/Length).
I can calculate an almost correct answer with the following code:
VB Code:
Dim dTheta As Double 'Exit tangent of clothoide
Dim dAlpha As Double 'Starting tangent
Dim dX As Double 'Opposite side of triangle formed by Start/End points and entry tangent
Dim dY As Double 'Adjacent side of triangle formed by Start/End points and entry tangent
Dim dRadius As Double 'Clothoide radius
'Calculate end radius of clothoide
dRadius = dParameter ^ 2 / dLength
'Calculate end tangent angle
dTheta = dLength / (2 * dRadius)
'Calculate sides of triangle
dX = dLength - (dLength ^ 5 / (10 * ((2 * dLength * dRadius) ^ 2))) _
+ (dLength ^ 9 / (216 * ((2 * dLength * dRadius) ^ 4))) _
- (dLength ^ 13 / (9360 * ((2 * dLength * dRadius) ^ 6))) _
+ (dLength ^ 17 / (685440 * ((2 * dLength * dRadius) ^ 8)))
dY = (dLength ^ 3 / (3 * (2 * dLength * dRadius))) _
- (dLength ^ 7 / (42 * ((2 * dLength * dRadius) ^ 3))) _
+ (dLength ^ 11 / (1320 * ((2 * dLength * dRadius) ^ 5))) _
- (dLength ^ 15 / (75600 * ((2 * dLength * dRadius) ^ 7))) _
+ (dLength ^ 19 / (6894720 * ((2 * dLength * dRadius) ^ 9)))
'Calculate missing angle
dAlpha = Atn(dY / dX)
But this solution gives an answer with an accuracy of +/- 0.001 gon and I need one order of magnitude more (ie. +/- 0.0001 gon or 0.0000015 radians).
I have done a search on the forum and tried changing the doubles to variants and using the cdec() function according to various posts but I always get the same answer.
Can anybody see a mistake in the code or advise as to the best way to acheive the required accuracy in the calculation?
Many Thanks
-
Aug 8th, 2002, 02:20 AM
#2
Well, ont that it would really belong in this forum, but have you tried writing your own data type? If you have a data type that holds several longs or doubles, then you can put it in a class and write functions to do all the operations you need.
Make sense?
-
Jul 31st, 2003, 12:43 PM
#3
Lively Member
Precision
Funny that you say you only get a +/-0.001 precision when using your code. I loaded it in VB6 and got the angle as:
Angle = 2.60028267012505E-02, or, without the *10^-2, is:
Angle = 0.0260028267012505, certainly with precision much, much larger than your reported +/-0.001, I would think. Don't you agree?
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
|