How to handle a double in CAD modeling

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);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值