用Balder根据两个三维点创建Cylinder

Balder中自动创建的Cylinder默认是处于垂直状态的,如果想要根据两个三维坐标创建一个圆柱,那么就需要对刚创建的Cylinder进行旋转操作。

private Cylinder CreatePipeCylinderFromGraphic(double x1,double y1,double z1,double x2,double y2,double z2,double Radius,Color color)
        {
            Cylinder cylinder = new Cylinder();                     

            double x0 = (x1 + x2) / 2;
            double y0 = (y1 + y2) / 2;
            double z0 = (z1 + z2) / 2;
            double length = Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + (z1 - z2) * (z1 - z2));
            cylinder.Size = length;
            double VirtualX = x1 - x0;
            double VirtualY = y1 - y0;
            double VirtualZ = z1 - z0;
            double A = VirtualX / (length / 2);
            double B = VirtualY / (length / 2);
            double C = VirtualZ / (length / 2);
            double AngleX = Math.Asin(C) * 180 / Math.PI;

            double AngleZ = Math.Atan(-A / B) * 180 / Math.PI;
            if (y1 < y2) AngleZ += 180;

            cylinder.Rotation = new Coordinate(AngleX, 0, AngleZ);
            cylinder.Position = new Coordinate(x0, y0, z0);

            
            cylinder.TopRadius = cylinder.BottomRadius = Radius;            
            cylinder.Color = color;
            cylinder.Segments = 20; //圆滑程度

            return cylinder;
        }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值