CAD 爆炸图算法

发布于 2024-10-27 13:39:44 字数 510 浏览 4 评论 0原文

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

Exploded view

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

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

Exploded view

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2024-11-03 13:39:44

你的问题相当广泛,因此我的解释变得有些冗长。我将提出两种用于轴向和径向处理的爆炸算法变体。

为了用示例来说明它们,我将使用以下数字(仅沿轴的边界框,仅五个部分):

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

当部件 P1P4 彼此完全接触时, P4P5 实际上是重叠的。

第一个是一种基本上按一个因子缩放距离的算法,例如您提出的。如果组件中的零件尺寸差异很大,而且重叠零件也如此(例如,在您的示例中,沿轴的圆形齿轮的延伸远小于钻头固定器),则会受到影响。

令缩放因子为f,则每个边界框的中心按f缩放,但扩展则不缩放。零件将是

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]

零件 P1'P4 之间的距离由下式给出

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 ,差异为零,但对于任何分解图的距离很大程度上取决于各个部件的尺寸。我认为如果尺寸变化较大,这看起来不会太好。

此外,对于重叠部分,

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

它们仍然重叠合理的 f。

另一种可能性是不定义轴的比例因子,而是定义恒定的零件距离d。然后边界框将如下对齐:

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,即重叠,以区分两个部分。

虽然该算法以(在我看来)更好的方式处理上述情况,但我们必须特别注意覆盖多个其他部分且不应包含在分组中的部分(例如,在您的情况下处理顶部)。

一种可能性是第一步将部件分组,然后将算法应用于这些组的边界框。之后,它可以再次应用于每一组中的零件,省略覆盖多个子组的零件。在你的情况下,它会是(注意嵌套分组是可能的):

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

你可能会看到我引入了两种不同类型的组:方括号中的部分/组由算法处理,即内部每个部分/子组之间添加一个间距这样的组,而圆括号内的组不会爆炸。

到目前为止,我们还没有处理径向爆炸,因为它很好地与轴处理解耦。但同样,这两种方法也可用于径向爆炸。但在我看来,第二种算法会产生更令人愉快的结果。例如,对于径向处理,可以按如下方式完成组:

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

在这种情况下,我们将附加组件 r 添加到第二组中的所有径向中心,并将 2*r 添加到所有径向中心在第三组中。

请注意,简单的缩放算法在没有特殊用户指导的情况下运行(一旦给出缩放因子),而第二个算法使用附加信息(分组)。

我希望这个相当长的解释能给您一些如何进一步进行的想法。如果我的解释在某些时候不清楚或者您还有其他问题,请随时发表评论。

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)

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

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]

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)

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.

Additionally for overlapping parts

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

they still overlap for reasonable f.

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文