private void Show_Field()
            {
                List <int> X = new List <int>(), Y = new List <int>(), Z = new List <int>();

                foreach (CutPlane p in Map_Planes.Items)
                {
                    if (p.axis == 0)
                    {
                        X.Add(p.pos);
                    }
                    else if (p.axis == 1)
                    {
                        Y.Add(p.pos);
                    }
                    else if (p.axis == 2)
                    {
                        Z.Add(p.pos);
                    }
                }

                List <List <Hare.Geometry.Point> > hpts = new List <List <Hare.Geometry.Point> >();

                FDTD.Pressure_Points(ref hpts, ref Pressure, X.ToArray(), Y.ToArray(), Z.ToArray(), 0.00002 * Math.Pow(10, (double)Param_Min.Value / 20), false, false, true, Magnitude.Checked);
                List <List <Rhino.Geometry.Point3d> > Pts = new List <List <Rhino.Geometry.Point3d> >();

                for (int i = 0; i < hpts.Count; i++)
                {
                    Pts.Add(new List <Rhino.Geometry.Point3d>());
                    for (int j = 0; j < hpts[i].Count; j++)
                    {
                        Pts[i].Add(RC_PachTools.HPttoRPt(hpts[i][j]));
                    }
                }

                P.Populate(X.ToArray(), Y.ToArray(), Z.ToArray(), FDTD.dx, Pressure, M, Magnitude.Checked);

                Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
            }
Пример #2
0
            public void Begin()
            {
                Random Rnd = new Random();

                for (int q = 0; q < RayCount; q++)
                {
                    Rhino.RhinoApp.SetCommandPrompt(string.Format("Finding Ray {0} of {1}", q, RayCount));
                    double SumLength = 0;
                    Pachyderm_Acoustic.Environment.OctaveRay R = Source.Directions(q, 0, ref Rnd).SplitRay(5);
                    double        u           = 0;
                    double        v           = 0;
                    int           ChosenIndex = 0;
                    Polyline      Ray         = new Polyline();
                    List <double> leg         = new List <double> {
                        0
                    };
                    List <int> code = new List <int> {
                        0
                    };
                    List <Hare.Geometry.Point> Start;
                    //List<int> IDs = new List<int>();
                    Ray.Add(RC_PachTools.HPttoRPt(R.origin));
                    List <double> P = new List <double> {
                        R.Intensity
                    };
                    do
                    {
                        R.Ray_ID = Rnd.Next();
                        if (Room.shoot(R, out u, out v, out ChosenIndex, out Start, out leg, out code))
                        {
                            double cos_theta;


                            for (int i = 0; i < Start.Count; i++)
                            {
                                Ray.Add(RC_PachTools.HPttoRPt(Start[i]));
                                //IDs.Add(-1);
                                R.Intensity *= Math.Pow(10, -.1 * Room.Attenuation(code[i])[5] * leg[i]);
                                SumLength   += leg[i];
                            }

                            R.origin  = Start[Start.Count - 1];
                            R.Surf_ID = ChosenIndex;
                            bool trans = (Rnd.NextDouble() < Room.TransmissionValue[ChosenIndex][5]);

                            Room.Absorb(ref R, out cos_theta, u, v);
                            Room.Scatter_Simple(ref R, ref Rnd, cos_theta, u, v);

                            if (trans)
                            {
                                R.direction *= -1;
                                R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            }
                            else
                            {
                                R.Intensity *= (1 - Room.TransmissionValue[ChosenIndex][5]);
                            }

                            P.Add((double)R.Intensity);

                            //if (Rnd.NextDouble() < Room.ScatteringValue[ChosenIndex].Coefficient(5))
                            //{
                            //    Room.Scatter_Simple(ref R, ref Rnd);
                            //    //Utilities.PachTools.Ray_Acoustics.LambertianReflection_Stoch(ref R.direction, ref Rnd, Room.Normal(ChosenIndex, u, v));

                            //    if (trans)
                            //    {
                            //        R.direction *= -1;
                            //        R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            //    }
                            //    else
                            //    {
                            //        R.Intensity *= Room.AbsorptionValue[ChosenIndex].Coefficient_A_Broad()[5];
                            //    }

                            //}
                            //else
                            //{
                            //    if (!trans)
                            //    {
                            //        Utilities.PachTools.Ray_Acoustics.SpecularReflection(ref R.direction, ref Room, ref u, ref v, ref ChosenIndex);
                            //        R.Intensity *= Room.AbsorptionValue[ChosenIndex].Coefficient_A_Broad()[5];
                            //    }
                            //    else
                            //    {
                            //        R.Intensity *= Room.TransmissionValue[ChosenIndex][5];
                            //    }
                            //}
                        }
                        else
                        {
                            //Rhino.RhinoDoc.ActiveDoc.Objects.AddLine(PachTools.HPttoRPt(R.origin), PachTools.HPttoRPt(R.origin + R.direction));
                            break;
                        }
                    }while (SumLength < CutoffLength);
                    //Poly_ID.Add(IDs);
                    if (SumLength > CutoffLength)
                    {
                        Ray.Add(RC_PachTools.HPttoRPt(R.origin));
                    }
                    RayList.Add(Ray);
                    Power.Add(P);
                }
            }