本文介绍了CAD的分解视图算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个程序来查看3D CAD模型,并希望构建自动分解视图。将要查看的所有装配都是轴对称的。有些可能不是,但大多数是。我想找出一种算法,用于将装配件中的零件自动移动到分解视图位置。这是我要通过算法实现的示例(当然要减去标签):

I'm making a program to view 3D CAD models and would like to build in automated exploded views. All the assemblies that will be viewed are axi-symmetric. Some may not be, but the majority are. I'd like to figure out an algorithm for automatically moving parts in an assembly into an exploded view position. Here is an example of what I want to achieve through an algorithm (minus the labels of course):

我需要处理的唯一值是每个零件的边界框的中心。如果需要的信息更多,我可以计算出更多的信息,但似乎就足够了。我想到的粗略方法是计算从装配体的原点到沿轴对称轴的每个零件中心的向量,然后计算相对于中心轴的零件中心的径向向量。从那里,我需要找出一些计算方法,以能够沿着这两个向量的某种组合来缩放每个零件的位置。那是我不太确定要朝哪个方向发展的部分。我所包含的图像显示了我想要的确切功能,但是我希望能够通过任何float值缩放位置,以展开或收缩爆炸视图,其中1.0是原始组装模型。有任何想法吗?

The only value I have to work with is the center of the bounding box of each part. If more information than that is needed, I can calculate more information, but it seems like it should be sufficient. The rough approach I have in mind is to calculate a vector from the origin of the assembly to the center of each part along the axi-symmetric axis, then calculate a radial vector to the center of the part with respect to the center axis. From there, I'd need to figure out some calculation that would be able to scale the position of each part along some combination of those two vectors. That's the part where I'm not quite sure what direction to go with this. The image I've included shows the exact functionality I'd like, but I want to be able to scale the position by any float value to expand or contract the exploded view, with 1.0 being the original assembled model. Any ideas?

推荐答案

您的问题涉及面很广,因此我的解释有些冗长。我将针对轴向和径向处理提出爆炸算法的两种变体。

Your question is quite broad and thus my explanation became somehow lengthy. I'll propose two variants of an explosion algorithm for both axial and radial treatment.

为了举例说明它们,我将使用以下数字(沿轴,仅五个部分):

To illustrate them with an example I'll use the following numbers (bounding boxes along the axis only, only five parts):

P1: [ 0,10] (battery)
P2: [10,14] (motor)
P3: [14,16] (cog)
P4: [16,24] (bit holder)
P5: [18,26] (gear casing)

零件 P1 到 P4 彼此完全接触, P4 和 P5 实际上重叠。

While parts P1 to P4 exactly touch each other, P4 and P5 actually overlap.

第一个算法是一种基本上按距离缩放距离的算法,例如您提出的。如果零件的大小在装配体中有很大不同,但对于重叠的零件(例如,沿轴的示例,圆形齿轮的延伸远小于钻头固定器的长度),则会受到影响。

The first one is an algorithm which basically scales the distances by a factor, such as you proposed. It will suffer if size of pieces is much different in an assembly but also for overlapping parts (e.g. in your example along the axis the extension of circle cog is much smaller than bit holder).

让比例因子为 f ,然后将每个边界框的中心缩放为 f ,但是扩展名不是。那么部分将是

Let the scaling factor be f, then the center of each bounding box is scaled by f, but extension is not. Parts then would be

P1:  5 + [-5,5]   => P1':  5*f + [-5,5]
P2: 12 + [-2,2]   => P2': 12*f + [-2,2]
P3: 15 + [-1,1]   => P3': 15*f + [-1,1]
P4: 20 + [-4,4]   => P4': 20*f + [-4,4]
P5: 22 + [-4,4]   => P5': 22*f + [-4,4]

零件之间的距离<$ c然后将$ c> P1'转换为 P4

The distance between the parts P1' to P4 is then given by

P2' - P1' : (12*f-2) - (5*f+5) = 7*(f-1)
P3' - P2' : (15*f-1) - (12*f+2) = 3*(f-1)
P4' - P3' : (20*f-4) - (15*f+1) = 5*(f-5)

正如预期的那样, f = 0 ,但对于任何分解图,距离很大程度上取决于各个零件的尺寸。如果大小变化较大,我认为这看起来不会太好。

As expected the difference is zero for f=0 but for any exploded view the distance strongly depends on the sizes of the separate parts. I don't think that this will look too good if variation of sizes is bigger.

此外,重叠部分

P5' - P4' : (22*f-4) - (20*f+4) = 2*f-8

对于合理的f,它们仍然重叠。

they still overlap for reasonable f.

另一种可能性是不为轴,但零件距离不变 d 。然后边界框将如下对齐:

Another possibility would be to define not a scaling factor for the axis but a constant part-distance d. Then bounding boxes would be aligned like the following:

P1': [ 0,10]
P2': [10,14]+d
P3': [14,16]+2*d
P4': [16,24]+3*d
P5': [18,26]+4*d+6

请注意,在最后一行中,我们添加了 24 -8 = 6 ,即为了区分两个部分的重叠。

Note that in the last line we added 24-8=6, i.e. the overlap in order to differentiate the two parts.

虽然此算法以更好的方式(我认为)可以处理上述情况,但我们必须对涵盖多个其他部分的部分添加特殊的注意,因此不应包括在内在分组中(例如,在您的情况下为顶部)。

While this algorithm handles the above mentioned cases in a (in my opinion) better way we have to add special care to parts which cover multiple other parts and should not be included in the grouping (e.g. handle top in your case).

一种可能性是,首先将零件分组,然后将算法应用于这些组的边界框。之后,可以将其再次应用于每个组中的部件,而忽略覆盖多个子组的部件。在您的情况下,这可能是(请注意可以进行嵌套分组):

One possibility would be to group the parts into groups in a first step and then apply the algorithm to the bounding box of these groups. Afterwards it can be applied to parts in each group again, omitting the parts which cover more than one subgroup. In your case it would be (note nested grouping is possible):

[
    ([battery,(switch,circuit switch),motor],handle top),
    motor cog,
    tri-cog,
    red-cog,
    circle-cog,
    bit-holder,
    (gear casing,spring,lock knob)
]

您可能会看到我介绍了两种不同的组:方括号中的零件/组由算法处理,即,在该组中的每个零件/子组之间添加了一个间距,而圆括号中的组不爆炸。

You might see that I have introduced two different kind of groups: parts/groups in square braces are handled by the algorithm, i.e. a spacing is added between each part/subgroup inside such a group, while the groups inside round braces are not exploded.

到目前为止,我们尚未处理径向爆炸,因为它很好地与轴处理脱钩。但是同样,两种方法也可以用于径向爆炸。但是我仍然认为第二种算法会产生更令人满意的结果。例如。可以按以下方式对这些组进行放射治疗:

Up to now we did not handled the radial explosion because it nicely decouples from the axis treatment. But again the same both approaches can be used for radial explosion also. But again in my opinion the second algorithm yields more pleasant results. E.g. the groups can be done as follows for radial treatment:

 [
     (battery,switch,<many parts>,gear casing),
     (switch,spring),
     (handle top, lock knob)
 ]

在这种情况下,我们将向第二组的所有径向中心和 2 *添加一个附加分量 r r 到第三组的所有人。

In this case we would add an additional component r to all radial centers in the second group and 2*r to all in the third group.

请注意,简单的缩放算法无需特殊的用户指导即可运行(一旦给出了缩放因子),而第二个使用附加信息(分组)。

Note that the simple scaling algorithm runs without special user guidance (once the scaling factor is given) while the second one uses additional information (the grouping).

我希望这段较长的解释能为您提供一些进一步操作的思路。如果我的解释有时不清楚,或者您还有其他疑问,请随时发表评论。

I hope this rather long explanation gives you some ideas how to proceed further. If my explanations are unclear at some point or if you have further questions please feel free to comment.

这篇关于CAD的分解视图算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 22:00