CAD 爆炸图算法
我正在制作一个程序来查看 3D CAD 模型,并希望构建自动分解视图。将看到的所有组件都是轴对称的。有些可能不是,但大多数是。我想找出一种算法,用于自动将组件中的零件移动到分解视图位置。这是我想通过算法实现的示例(当然不包括标签):
我必须使用的唯一值是每个部分的边界框的中心。如果需要更多的信息,我可以计算更多的信息,但看起来应该足够了。我想到的粗略方法是计算沿轴对称轴从装配体原点到每个零件中心的矢量,然后计算相对于中心轴到零件中心的径向矢量。从那里,我需要找出一些计算,能够沿着这两个向量的某种组合缩放每个部分的位置。这就是我不太确定该朝哪个方向发展的部分。我包含的图像显示了我想要的确切功能,但我希望能够通过任何浮点值缩放位置以扩展或收缩爆炸视图,其中 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):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题相当广泛,因此我的解释变得有些冗长。我将提出两种用于轴向和径向处理的爆炸算法变体。
为了用示例来说明它们,我将使用以下数字(仅沿轴的边界框,仅五个部分):
当部件
P1
到P4
彼此完全接触时,P4
和P5
实际上是重叠的。第一个是一种基本上按一个因子缩放距离的算法,例如您提出的。如果组件中的零件尺寸差异很大,而且重叠零件也如此(例如,在您的示例中,沿轴的圆形齿轮的延伸远小于钻头固定器),则会受到影响。
令缩放因子为
f
,则每个边界框的中心按f
缩放,但扩展则不缩放。零件将是零件
P1'
到P4
之间的距离由下式给出正如预期的那样,对于
f=0
,差异为零,但对于任何分解图的距离很大程度上取决于各个部件的尺寸。我认为如果尺寸变化较大,这看起来不会太好。此外,对于重叠部分,
它们仍然重叠合理的 f。
另一种可能性是不定义轴的比例因子,而是定义恒定的零件距离
d
。然后边界框将如下对齐:请注意,在最后一行中我们添加了 24-8=6,即重叠,以区分两个部分。
虽然该算法以(在我看来)更好的方式处理上述情况,但我们必须特别注意覆盖多个其他部分且不应包含在分组中的部分(例如,在您的情况下处理顶部)。
一种可能性是第一步将部件分组,然后将算法应用于这些组的边界框。之后,它可以再次应用于每一组中的零件,省略覆盖多个子组的零件。在你的情况下,它会是(注意嵌套分组是可能的):
你可能会看到我引入了两种不同类型的组:方括号中的部分/组由算法处理,即内部每个部分/子组之间添加一个间距这样的组,而圆括号内的组不会爆炸。
到目前为止,我们还没有处理径向爆炸,因为它很好地与轴处理解耦。但同样,这两种方法也可用于径向爆炸。但在我看来,第二种算法会产生更令人愉快的结果。例如,对于径向处理,可以按如下方式完成组:
在这种情况下,我们将附加组件
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):
While parts
P1
toP4
exactly touch each other,P4
andP5
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 byf
, but extension is not. Parts then would beThe distance between the parts
P1'
toP4
is then given byAs 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
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: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):
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:
In this case we would add an additional component
r
to all radial centers in the second group and2*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.