Results 1 to 3 of 3

Thread: Correcting Lines which are slightly off the axis

  1. #1
    Active Member
    Join Date
    2005-03
    Location
    From Kerala, Currently located at Bangalore, India
    Posts
    95
    Login to Give a bone
    0

    Unhappy Correcting Lines which are slightly off the axis

    Guys,
    I have a drawing in which all the lines are slightly off the axis. That means, It can be 0.0003495 degree, 0.008565 degree, 0.0306795 degree etc...instead of a horizontal line. I though of writing a macro to correct these lines. But, the final rotation is not happening properly.Can someone help me..??


    Code:
    Private Sub CommandButton1_Click()
    Me.Hide
        Dim LineObject As AcadLine
        Dim StPo As Variant
        Dim BasePoints(0 To 2) As Double
        Dim Sset As AcadSelectionSet
        Dim LAng, rotationAngle As Double
        Dim Ang As Integer
        
        Set Sset = ThisDrawing.ActiveSelectionSet
        Sset.SelectOnScreen
        
        For Each LineObject In Sset
            StPo = LineObject.StartPoint
            
            BasePoints(0) = StPo(0)
            BasePoints(1) = StPo(1)
            BasePoints(2) = StPo(2)
                                
            LAng = LineObject.Angle ' Stores the angle a Double
            Ang = LAng ' Stores the angle as integer
            rotationAngle = LAng - Ang ' Gets the difference in Angle
            
            rotationAngle = rotationAngle * 0.0174532925 ' Converting angle to radians
    
            LineObject.Rotate BasePoints, rotationAngle
            Update
        Next
    Me.Show
    End Sub
    Last edited by Ed Jobe; 2009-02-04 at 04:16 PM. Reason: Added Code tags.

  2. #2
    AUGI Addict MikeJarosz's Avatar
    Join Date
    2015-10
    Location
    New York NY
    Posts
    1,497
    Login to Give a bone
    0

    Default Re: Correcting Lines which are slightly off the axis

    In many cases, total precision is not possible in modern computers. This comes as a huge suprise to software users who expect computers to calculate with infinite accuracy. The explanation lies with the number systems used inside the computer.

    In your code you use the dim.....as double statement. What is a double? One of my VBA manuals defines double as "4.94E-324 to 1.8E+308 approximately". Pretty strange numbers, huh? These are called floating point in computer science jargon. They have many interesting properties. One very interesting property: it is not possible to represent every number in floating point ! It is inherently inacurate.

    We see numbers like .00000002, .00000523, etc in Acad all the time. I won't say that this is always a floating point issue, but it is a real possibility. I once watched a colleague obsessed with perfection trying to force the XYX coordinates of some lines to be certain set values. After a full day of frustration, she gave up.

    A good discussion of "The Perils of Floating Point" by Bruce M. Bush can be found here:

    http://www.lahey.com/float.htm

    Did you know zero can be positive or negative in floating point? By the way, all your computations are actually being done in binary.......with its own set of peculiarities.

    The floating point standard used by most computer hardware and software manufacturers today was created by a Canadian mathematician William Kahan, who is alive and well, teaching at Berkeley.

    http://en.wikipedia.org/wiki/William_Kahan

    Google his math papers. He has a terrific sense of humor (mathemetician style).

  3. #3
    Active Member
    Join Date
    2007-12
    Posts
    68
    Login to Give a bone
    0

    Default Re: Correcting Lines which are slightly off the axis

    Check out the "Debug.print" command.

    It will show you that you are trying to round down in RADIANS. You will end up with Integers of 0,1,2 or 3. Thats it. The closest "Snap" you will end up with is a bit over 120 degrees.

    Then, for reasons unknown, you decide to convert your radians, to radians. It doesnt work like that.

    You are reading in radians from the .Angle property, and you are writing out radians in your .Rotation method. As unintuitive as it sounds, stick with the radians. Every time you convert, you lose a bit more accuracy.

    Try the following Function. You pass the Function the actual angle, in radians, of your line, in the parameter called "CurrentAngle". Pass it the *resolution*, in degrees, you want it to round to (180 makes all horizontal lines, 90 makes either horizontal or vertical, 45 ghets you inbetween ,ect) in the "ResAngle" parameter. It returns a value, in radians, that you want to use as your rotation parameter.

    For instance: pass a line angle, just over 45 degrees (.79 in radians), and return the amount needed to rotate it to the nearest 90 degree increment

    Dim retAngle as double
    RetAngle=RotateAmount(0.79, 90) ' returns 0.780796326794897

    '------------- snip-----------------------

    Function RotateAmount(CurrentAngle As Double, ResAngle As Double) As Double
    Const Deg2Radn As Double = 1.74532925199433E-02
    Dim ResInRadians As Double
    Dim NumberOfIncrements As Double
    Dim RoundedAngle As Double

    ResInRadians = (ResAngle * Deg2Radn)
    NumberOfIncrements = CurrentAngle / ResInRadians

    If NumberOfIncrements - Int(NumberOfIncrements) < 0.5 Then
    NumberOfIncrements = Int(NumberOfIncrements)
    Else
    NumberOfIncrements = Int(NumberOfIncrements) + 1
    End If

    RoundedAngle = NumberOfIncrements * ResInRadians
    RotateAmount = RoundedAngle - CurrentAngle

    End Function

Similar Threads

  1. slightly off axis
    By wadeshuey in forum Revit Architecture - General
    Replies: 0
    Last Post: 2010-09-21, 04:10 PM
  2. Slightly Off Axis
    By sthedens in forum Revit Architecture - General
    Replies: 4
    Last Post: 2010-08-12, 07:14 PM
  3. Correcting off-axis section?
    By anders.hedman in forum Revit Architecture - General
    Replies: 5
    Last Post: 2009-11-02, 05:01 PM
  4. Script / API to clean up “Line slightly off axis”
    By brenehan in forum Revit Architecture - General
    Replies: 6
    Last Post: 2009-06-13, 02:52 PM
  5. Error element is slightly off axis
    By sonya in forum Revit Architecture - General
    Replies: 5
    Last Post: 2007-06-07, 02:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •