Helixtoolkit How do I make bent tube

2019-08-17 11:34发布

Helixtoolkitte I need to bend the pipe for this, I have prepared the code for this, but I need xml in ModelVisual3D. The code I've prepared is below. That's not what I want. I want it to come when I click a button. If you have different ways, can you help? A click should form a flat tube and a trapezoid tube.But it does not occur. why not? xaml:

<Window x:Class="StreamlinesDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:t="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
        Title="StreamlinesDemo" Height="485.232" Width="643.924">
    <Grid>
        <t:HelixViewport3D x:Name="view1" ShowCoordinateSystem="True" Margin="0,31,120,21" >
            <t:DefaultLights/>
            <ModelVisual3D x:Name="Model" Content="{Binding StreamLinesModel}"/>
        </t:HelixViewport3D>
        <TextBox x:Name="txt1" HorizontalAlignment="Left" Height="23" Margin="521,74,-5,0" TextWrapping="Wrap" Text="3" VerticalAlignment="Top" Width="120"/>
        <TextBox x:Name="txt2" HorizontalAlignment="Left" Height="23" Margin="521,102,-5,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="120"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="521,158,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
        <Label x:Name="lbl1" Content="Label" HorizontalAlignment="Left" Margin="544,183,0,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txt3" HorizontalAlignment="Left" Height="23" Margin="521,130,-5,0" TextWrapping="Wrap" Text="90" VerticalAlignment="Top" Width="120"/>
    </Grid>
</Window>

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        double R = 1;
        //velocity
        double x = 0.001, y = 0;
        double indirilenx , indirileny ;
        //public int sayac = 0;
        public GeometryModel3D StreamLinesModel { get; set; }
        public double U = 0.5;
        double referansbaslangıcx=0, referansbaslangıcy=0, referansbaslangıcz=0;
        double derecedegis = 0;
        private void tup(double x, double y, double z, double lengh,double derece)
        {
            TubeVisual3D tube1 = new TubeVisual3D();
             //ilk boru
             tube1.Path.Add(new Point3D(x, y, z));// başlangıç
            derecedegis += derece;
            referansbaslangıcx += lengh * Math.Sin(Math.PI * derecedegis / 180);
            referansbaslangıcy += lengh * Math.Cos(Math.PI * derecedegis / 180);
            referansbaslangıcz = z;
            tube1.Path.Add(new Point3D(referansbaslangıcx, referansbaslangıcy, z));//bitiş 
             tube1.Diameter = 1;
             view1.Children.Add(tube1);
        }
       MeshBuilder mb = new MeshBuilder(true, true);
        public void bukulmusboru(double xx,double yy,double z,double derece)
        {   if(derece/360!=0)
            {
                double yeniderece;
                if (derece % 90 != 0)
                    yeniderece = derece % 90;
                else
                    yeniderece = derece;
            DataContext = this;
            const double dt = 0.1;
             int nSteps =Convert.ToInt32(yeniderece);
            var p0 = new Point(xx, yy);//baslangıç bükülmüş
            Point[] pts = Solve(Velocity, p0, dt, nSteps);
            var vel = new double[pts.Length];
            var diam = new double[pts.Length];
            int i = 0;
            var pts3d = new Point3D[pts.Length];
            double vmax = 0;
            foreach (Point pt in pts)
            {
                pts3d[i] = new Point3D(pt.X, pt.Y, 0);
                double v = Velocity(pt.X, pt.Y).Length;
                referansbaslangıcx = pt.X;
                referansbaslangıcy = pt.Y;
                if (v > vmax) vmax = v;
                vel[i++] = v;
                //sayac++; 
            }
            for (int j = 0; j < vel.Length; j++)
                vel[j] = 1;
            for (int j = 0; j < vel.Length; j++)
                diam[j] = 1;
            mb.AddTube(pts3d, vel, diam, 48, false);
            StreamLinesModel = new GeometryModel3D();
            StreamLinesModel.Geometry = mb.ToMesh();
            StreamLinesModel.Material = Materials.Hue;
            StreamLinesModel.BackMaterial = Materials.Hue;
            }
        }
        public Point[] Solve(Func<double, double, Vector> f, Point p0, double dt, int n)
        {
            Point p = p0;
            var result = new Point[n];
            for (int i = 0; i < n; i++)
            {
                result[i] = p;
                p = p + f(p.X, p.Y) * dt;
            }
           // sayac = 0;
            return result;
        }
        public Vector Velocity(double xx, double yy)
        {
           // sayac++;
            if (topla/90==1)
            {
                x = 2 * Math.PI * R * indirilenx /360; ;
                y = 2 * Math.PI * R * indirileny /360;
                indirileny--;
                indirilenx--;
            }
            if (topla / 90 == 2)
            {
                x = 2 * Math.PI * R * indirilenx / 360; ;
                y = 2 * Math.PI * R * indirileny / 360;
                indirileny++;
                indirilenx--;
            }
            if (topla / 90 == 3)
            {
                x = 2 * Math.PI * R * indirilenx / 360; ;
                y = 2 * Math.PI * R * indirileny / 360;
                indirileny--;
                indirilenx++;
            }
            if (topla / 90 == 4)
            {
                x = 2 * Math.PI * R * indirilenx / 360; ;
                y = 2 * Math.PI * R * indirileny / 360;
                indirileny++;
                indirilenx++;
            }
            double u = x;
            double v = y;
            return new Vector(u, v);
        }
        // http://mathdemos.gcsu.edu/mathdemos/gowiththeflow/HTMLLinks/index_16.html
       public int cift = 0;
        double topla=0;
       public double l, a, r;
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            l = Convert.ToDouble(txt1.Text);
          r= Convert.ToDouble(txt2.Text);
           a= Convert.ToDouble(txt3.Text);
            this.x = 0.001; this.y = 0;
             //topla = a + topla;
            indirilenx = 90; indirileny = 0;
          //  sayac = 0;
            topla += indirilenx;
            if (topla / 90 == 2)
            {
                indirilenx = 0; indirileny = -90;
            }
            if (topla / 90 == 3)
            {
                indirilenx = -90; indirileny = 90;
            }
            if (topla / 90 == 4)
            {
                indirilenx = 0; indirileny = 90;
            }
            DataContext = this.Activate();
            tup(referansbaslangıcx, referansbaslangıcy, referansbaslangıcz, l, a);
            bukulmusboru(referansbaslangıcx, referansbaslangıcy, referansbaslangıcz, a);
            cift++;
            lbl1.Content = ""+cift;
        }
    }

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-17 11:57

Your StreamLinesModel didn't implement INotifyPropertyChanged. Wpf binding relys on this interface.

查看更多
登录 后发表回答