首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ModelVisual3D的中心

ModelVisual3D的中心
EN

Stack Overflow用户
提问于 2011-12-23 20:46:17
回答 3查看 2.2K关注 0票数 2

我有一个ModelVisual3D,里面有几个立方体。如果我想要旋转整个组的中心,我该怎么做呢?

下面是我的代码:

代码语言:javascript
复制
RotateTransform3D rt;
AxisAngleRotation3D ar;
Transform3DGroup grp;

rt = new RotateTransform3D();
ar = new AxisAngleRotation3D();                     

ar.Axis = new Vector3D(1, 0, 0);
ar.Angle = x; //x a value 0-360
rt.Rotation = ar;
rt.CenterX = //*Here i need the center of the ModelVisual3D X*
rt.CenterY = //*Here i need the center of the ModelVisual3D Y*
rt.CenterZ = //*Here i need the center of the ModelVisual3D Z*

grp = new Transform3DGroup();
grp.Children.Add(rt);

cubes.Transform = grp; //cubes is the ModelVisual3D object that i want to rotate
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-12-23 21:11:12

你可以计算所有点的平均值。P-Code:

代码语言:javascript
复制
Point avg
for (point in points)
    avg = avg + point
    ++count

avg /= count

这就是你的中心。

在一个简单的物理模拟中,您将为每个点添加一个权重。

票数 2
EN

Stack Overflow用户

发布于 2012-11-02 09:43:57

代码语言:javascript
复制
public Point3D GetCenter(ModelVisual3D model)
{
    var rect3D = Rect3D.Empty;
    UnionRect(model, ref rect3D);
    _center = new Point3D((rect3D.X + rect3D.SizeX / 2), (rect3D.Y + rect3D.SizeY / 2), (rect3D.Z + rect3D.SizeZ / 2));
    return _center;
}

private void UnionRect(ModelVisual3D model, ref Rect3D rect3D)
{
    for (int i = 0; i < model.Children.Count; i++)
    {
        var child = model.Children[i] as ModelVisual3D;
        UnionRect(child, ref rect3D);
    }
    if (model.Content != null)
        rect3D.Union(model.Content.Bounds);
}
票数 2
EN

Stack Overflow用户

发布于 2016-04-15 06:14:38

一旦你知道怎么做,就很容易了:

代码语言:javascript
复制
Rect3D d1 = MeshGeometry3D_1.Bounds;
d1.Union(MeshGeometry3D_2.Bounds);
// to the center of the block:
Vector3D cVect = new Vector3D(d1.SizeX / 2, d1.SizeY / 2, d1.SizeZ / 2);           
columnModel.Transform = new TranslateTransform3D(-cVect);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8616266

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档