Results 1 to 3 of 3

Thread: Accuracy of VB calculations (again...)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Location
    Madrid
    Posts
    9

    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:
    1. Dim dTheta As Double           'Exit tangent of clothoide
    2. Dim dAlpha As Double           'Starting tangent
    3. Dim dX As Double               'Opposite side of triangle formed by Start/End points and entry tangent
    4. Dim dY As Double               'Adjacent side of triangle formed by Start/End points and entry tangent
    5. Dim dRadius As Double          'Clothoide radius
    6.  
    7. 'Calculate end radius of clothoide
    8. dRadius = dParameter ^ 2 / dLength
    9.  
    10. 'Calculate end tangent angle
    11. dTheta = dLength / (2 * dRadius)
    12.  
    13. 'Calculate sides of triangle
    14. dX = dLength - (dLength ^ 5 / (10 * ((2 * dLength * dRadius) ^ 2))) _
    15.              + (dLength ^ 9 / (216 * ((2 * dLength * dRadius) ^ 4))) _
    16.              - (dLength ^ 13 / (9360 * ((2 * dLength * dRadius) ^ 6))) _
    17.              + (dLength ^ 17 / (685440 * ((2 * dLength * dRadius) ^ 8)))
    18.  
    19. dY = (dLength ^ 3 / (3 * (2 * dLength * dRadius))) _
    20.      - (dLength ^ 7 / (42 * ((2 * dLength * dRadius) ^ 3))) _
    21.      + (dLength ^ 11 / (1320 * ((2 * dLength * dRadius) ^ 5))) _
    22.      - (dLength ^ 15 / (75600 * ((2 * dLength * dRadius) ^ 7))) _
    23.      + (dLength ^ 19 / (6894720 * ((2 * dLength * dRadius) ^ 9)))
    24.  
    25. 'Calculate missing angle
    26. 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

  2. #2
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555
    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?

  3. #3
    Lively Member
    Join Date
    Apr 2003
    Location
    Georgetown, Texas
    Posts
    114

    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
  •  



Click Here to Expand Forum to Full Width