How to handle a double in CAD modeling

来源:互联网 发布:计算机二级vb题库 编辑:程序博客网 时间:2024/06/05 10:19

1. The way of Kbool.

            http://boolean.klaasholwerda.nl/algdoc/basicstepsframe.html

            Assuming the input data is supplied in doubles, the coordinates will be converted to 64bit integers.
            This is done using two scale factors, DGRID and GRID.
            DGRID defines the accuracy  the user wants
            an accuracy of two digits means DGRID should be set to  DGRID = 0.01

            Although in the boolean algorithm the accuracy is higher, the end result will be rounded to the DGRID.

            GRID defines the number of digits the boolean algorithm will use to calculate extra intersection.
            If for instance two segments intersect the intersection point does not have to be on the GRID.
            If the GRID would be set to 1, there would be no integer number in between to define this intersection point.
            With the GRID set to 100 there is place for those intersections, in this case the intersection point would be (50,50).

            In fact the algorithm uses a kind of integer fixed point calculation for coordinates, the fractional part is always fixed (least significant 2 digits) .

            For instance if the DGRID = 0.01 and GRID = 100 and the original polygon point is (1234.56,4567.89).
            The following coordinate will be used inside the boolean algorithms  (12345600,45678900).
            So multiplied by 1/DGRID converts the doubles to integers.
            GRID = 100  means multiply those integers with an extra factor to create space for the boolean algorithm to create intersections in between.
            In the end all points will be converted back to double with an accuracy of DGRID.
            This means all new intersection points will also be rounded to the DGRID in the end, if the user wants those intersection to be more accurate
            than his input data, the DGRID should be set smaller than the accuracy of the input data.

 

 

2. Transform a double to the nearest int:

for example: 0.999 to 1 and -0.999 to -1

Two ways:

(1): floor(doubleer+0.5)

(2):

if (doubleer > 0)

{

    return (int)(doubleer+0.5);

}

else

{

    return (int)(doubleer-0.5);

}

 

原创粉丝点击