Measure of distances in VBA

Hi everybody again ,

I have a doubt that may be anybody can help me:

When I have two elements connected between them vertex to vertex or vertex to any point of the another line , the distance must be = 0 , but I see that if I use the equation of the line like using the method ComputeMinimumDistance of the BsplineCurve , it returns me values more bigger than 0 , like  exponent -4 or similars in any cases.

Usually I obtain , when two elements are connect , values like Exp -12 or similar , but in any cases like I say of -4 aprox.

Anybody knows if there is any solution to it ,  like configure the work units or similar ???

If more information is needed or I have no explained me correctly , please let me know and I will explain better.

Thanks for your help in advanced.

Regards !!

Parents
  • Hi Xavi García,

    Jon wrote the most important facts I think, so just a few more comments:

    To understand what floating point number are, how they are implemented and what risks and threats exist there is mandatory knowledge for any CAD computation in my opinion. No deep detail experience is rewquired, just to understand basics and accept the most imporant things (like "test numbers equality is nonse ;-) and to know best practices. Wiki page mentioned by Jon is good start, but you can find plenty of articles and blogs on Internet (e.g. this one).

    Unknown said:
    When I have two elements connected between them vertex to vertex or vertex to any point of the another line , the distance must be = 0

    No, no and once more no ;-) ... well, in theory on paper the distance is zero, but the core question is how it's implemented in a particular software plus how it's maintained (or crippled) by API. And because no floating point number is exact, is e.g. 1E-10 still valid value or it's zero? If your master units are meters, if working in GIS and cadastre, anything under 1 mm is "zero" because it's below precision how data are captured. So 1E-4 (0.1 mm) can be always evaluated as 0 ... but it's not how simple API works.

    Unknown said:
    like configure the work units or similar

    From general perspective, if any code depends on units configuration, it's bad and fragile code.

    If you work with coordinates comming from differenct source (e.g. two elements), you should not use "simple math methods" like Point2dEqual, but Point2dEqualTolerance method, because it allows to define what is "below reasonable precision". Or you can implement own methods.

    BTW It can be valuable to check some API or solution where precision and difference between math and implementation is important. I am talking about topology and GIS libraries, because any topology is always calculated with "what is enough precision" in mind and it's reflected in API also.

    Unknown said:
     ComputeMinimumDistance of the BsplineCurve

    As Jon wrote, BSpline is calculated element and it cannot be treated in the same way as e.g. line or line string.

    With regards,

    Jan

  • OK Jon , I understand for what you say that a distance of 0.1mm must be considered 0 for microstation ??? I supose that a value of a exponent -10 or -12 is considered like a 0 , but a -4 ....

    Like I say , I have implemented my own method to calculate the distance , aplying the projection perpendicular of a point over a line , and it returns me the same value than methods like computeMinimumdistance of Bsplit , I must understand that I will not obtain a better precision of the connection ???.

    Thanks so much for your help Jan !!!
  • Unknown said:
    that a distance of 0.1mm must be considered 0 for microstation ???

    Not for MicroStation. MicroStation is not involved in such evaluation! MicroStation can be treated as "element storage" and it's defined that element coordinates (like in other CAD systems) are stored as floating decimal point numbers accordingly to IEEE standard. It's completely your responsibility to define what precision is critical for you (but it cannot be better than precision ensured by the storage itself). Every tool in MicroStation does the same: It works based on the precision specification ... e.g. element placemetn is not critical, but 3D modeling using Parasolid require some extra precision settings.

    Unknown said:
    I supose that a value of a exponent -10 or -12 is considered like a 0 , but a -4

    Again, it's you responsibility to research precision condition. Don't suppose, do serious math evaluation: What are your coordinates (in floating point math numbers close to zero have higher precision than big values numbers), what is required precision, with what precision you API works...

    Unknown said:
    I must understand that I will not obtain a better precision of the connection

    What is better precision? It sounds to me like magic things or nonsense form math point of view:

    • If there is line endpoint, I can probably easily make assignment like end-point-line-A = end-point-line-B, because it's only about to copy values from one structure to another.
    • But if there is any more complex element (arc, curve...), the coordinates are "not free" because of element constrains ... arc and circle has to have the same distance from center point, curve is calculated somehow, so it's not possible to do simple "structure copy" line-endpoint to curve-endpoint.
    • Any coordinate based on calculation like snap to curve, project to element etc. is always calcualted with limited precision.

    At the end, to work with B-splines required pretty good konwledge of B-splines math itself and also at least basics of precision concept in path extended by floating point implementation issues knowledge (and VBA limitations knowledge in this case also). And maybe it's the reson why so many software (GIS / topology / analysis, modeling and visualization etc.) work with linear geometry only.

    Regards,

      Jan

  • It's not just MicroStation. I do development for AutoCAD Civil 3D as well as MicroStation and have the same kinds of issues with floating point numbers in both. It doesn't matter if it's a calculation along a b-spline in MicroStation or distance from a Survey Point to an Alignment in Civil 3D.

    I wrote a VBA tip a few years ago on one way to handle it.
    envisioncad.com/.../comparing-floating-point-numbers

    Rod Wing
    Senior Systems Analyst

  • Unknown said:
    I wrote a VBA tip a few years ago on one way to handle it

    Good tip!

    MicroStation VBA has functions that do something similar for the UDTs.  For example...

    • Point2dEqualTolerance (p1, p2, tolerance)
    • Point3dEqualTolerance (p1, p2, tolerance)
    • Vector3dEqualTolerance (v1, v2, tolerance)
    • BsplineCurve.ComputeMinimumDistance (ClosestPoint, ClosestParameter, FromPoint, Rotation [, Tolerance])
    • Range3dEqualTolerance (Range0, Range1, Tolerance)
    • IntersectRay3d (IntersectionPoint, Parameters, Ray [, Tolerance])

     
    Regards, Jon Summers
    LA Solutions

  • Unknown said:

    RodWing
    I wrote a VBA tip a few years ago on one way to handle it

    Good tip!

    MicroStation VBA has functions that do something similar for the UDTs.  For example...

    • Point2dEqualTolerance (p1, p2, tolerance)
    • Point3dEqualTolerance (p1, p2, tolerance)
    • Vector3dEqualTolerance (v1, v2, tolerance)
    • BsplineCurve.ComputeMinimumDistance (ClosestPoint, ClosestParameter, FromPoint, Rotation [, Tolerance])
    • Range3dEqualTolerance (Range0, Range1, Tolerance)
    • IntersectRay3d (IntersectionPoint, Parameters, Ray [, Tolerance])

    Thank you.

    Unfortunately the AutoCAD and Civil 3D API's lack a lot of those types of functions which means I have to develop my own.

    To help make modules more portable between AutoCAD and MicroStation I will use my own utility functions in MicroStation applications even if there is something comparable available in the MicroStation API.

    I wrote a tip on that too! :)

    http://envisioncad.com/tips/create-portable-functions/

    Rod Wing
    Senior Systems Analyst

  • Thank you very much , I think that I can use the function you have posted "IsPointOnLine" to determinate if a Point is connected to a line , but if the precision of the distance between point and line is the precision of the value of the variable Zero I'm with the same problem ...

    I'll try with it !!

    Thanks again for your help Jon , Jan and Rodwing !!!

  • Unknown said:
    If the precision of the distance between point and line is the precision of the value of the variable Zero I'm with the same problem ...

    ZERO is defined as a constant value in Rod's VBA project.  If you don't like the value he's chosen, you can define a different value.

     
    Regards, Jon Summers
    LA Solutions

  • Yes Jon , I know it , but I supose that the value of constant zero is a value defined to determinate the minimum value of zero ... and in My macro If I define more small value of zero I will no detect elements conected ...

    Thanks again for your help !!!
  • Unknown said:
    I suppose that the value of constant zero is a value defined to determinate the minimum value of zero ... and in my macro If I define more small value of zero I will no detect elements conected ...

    Welcome to computer programming!  If this stuff were easy, then anybody could do it  8-)

     
    Regards, Jon Summers
    LA Solutions

  • jajaj it's true , but I have been programming during any years Joan !!! I know what you say ... but I'm new in world of cartography ...

    Thanks again !!
  • Unknown said:

    Welcome to computer programming!  If this stuff were easy, then anybody could do it  8-)

     
    Thanks Jon.  Finally someone admits this.  People around here (my work place) seem to think it's just so easy to program, but I think they don't ever get into the details.  I think that not many have written anything outside of school assignments.  The pitfall which this thread is focused on actually made me want to give up on mvba macros when I started.  Fortunately I did not give up and the resulting macros have been very rewarding.
     
    Just a thought,
    Minion

    Code... We're the good guys now.

Reply
  • Unknown said:

    Welcome to computer programming!  If this stuff were easy, then anybody could do it  8-)

     
    Thanks Jon.  Finally someone admits this.  People around here (my work place) seem to think it's just so easy to program, but I think they don't ever get into the details.  I think that not many have written anything outside of school assignments.  The pitfall which this thread is focused on actually made me want to give up on mvba macros when I started.  Fortunately I did not give up and the resulting macros have been very rewarding.
     
    Just a thought,
    Minion

    Code... We're the good guys now.

Children
No Data