TranslateCoordinates troubles

Discussion in 'AutoCAD' started by MickyV, Apr 7, 2004.

  1. MickyV

    MickyV Guest

    I'm trying to translate coordinates that I've picked using GetPoint from WCS coords to the current UCS, so I can then compare the X value for equivalency in the working coordinate system, but, even though OrthoMode is on, I'm getting a difference of 0.00000000001 between the two. I'm trying to test for perfect vertical positioning between the two points, which it should be given that OrthoMode is on, yet this inaccuracy is throwing it out.

    Is there any way to kill off this inaccuracy in translation, or should I just round it off to a few less decimal places before comparing the values?

    Thanks in advance,
    Mick.
     
    MickyV, Apr 7, 2004
    #1
  2. Hi Mick,

    The best way to compare two real values is with code like:

    If Abs(Var1 - Var2) < 0.0001 (or what ever) Then ' the values are the same.

    --


    Laurie Comerford
    CADApps
    www.cadapps.com.au


    WCS coords to the current UCS, so I can then compare the X value for
    equivalency in the working coordinate system, but, even though OrthoMode is
    on, I'm getting a difference of 0.00000000001 between the two. I'm trying to
    test for perfect vertical positioning between the two points, which it
    should be given that OrthoMode is on, yet this inaccuracy is throwing it
    out.
    just round it off to a few less decimal places before comparing the values?
     
    Laurie Comerford, Apr 7, 2004
    #2
  3. MickyV

    wivory Guest

    I agree. I've written substitute functions for using when comparing reals, not only for equality but other comparisons. For example if you only want to do something if one value is greater than another you need to make sure it's *really* greater and not just a rounding discrepancy. Here are a couple of them:

    [pre]
    Const NEGLIGIBLE As Single = 0.005
    '
    Private Function Equal(var1 As Variant, var2 As Variant) As Boolean
    Equal = Abs(var1 - var2) < NEGLIGIBLE
    End Function
    '
    Private Function FirstIsGreater(FirstVar As Variant, SecondVar As Variant) As Boolean
    FirstIsGreater = FirstVar - SecondVar > NEGLIGIBLE
    End Function
    [/pre]

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Apr 8, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.