コード例 #1
0
        public Edge_Curved(ref IEnumerable<Hare.Geometry.Point> SPT, ref IEnumerable<Hare.Geometry.Point> RPT, Environment.Medium_Properties Env_Props, Brep[] B, int[] Brep_Index, Curve i)
            : base(B, i)
        {
            //if (i.IsLinear()) throw new Exception("Curved Edge object called for straight edge.");
            //Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(i);
            ParentBreps = Brep_Index;
            
            //Get the open wedge angle. This needs the source location, and occlusion info...
            //Assuming tangent angles are always correctly oriented...
            //Vector Z_Dir = PointA - PointB;
            //double length = Z_Dir.Length();
            //Z_Dir.Normalize();
            //double MinAngle = double.PositiveInfinity;
            //Hare.Geometry.Point[] Dpt = new Hare.Geometry.Point[0];

            //Find the secondary source spacing DeltaZ
            /// 1/4 wavelength substituted for now...
            double fs = 88200; //Hz.
            //double DeltaZ = speed_of_sound / (fs * Math.Cos(MinAngle));//TODO: Adjust depending on distance from source to receiver... (nearest, farthest?
           
            /////
            //double El_Ct = Math.Ceiling(i.GetLength() / DeltaZ);
            //DeltaZ = i.GetLength() / El_Ct;
            //List<Point3d> Pts;
            double length = Env_Props.Sound_Speed(i.PointAtStart)/ (8 * fs);
            double total_length = i.GetLength();
            double t;
            
            //for (int j = 1; j < Pts.Length; j++)
            while (true)
            {
                if (!i.LengthParameter(length, out t)) break;
                Plane P;
                i.PerpendicularFrameAt(t, out P);
                Curve[] Csects1, Csects2;
                Point3d[] Psects;

                //double DeltaZ = Env_Props.Sound_Speed(Point3d.Origin) / (4 * fs);
                Rhino.Geometry.Intersect.Intersection.BrepPlane(B[0], P, 0.001, out Csects1, out Psects);
                Rhino.Geometry.Intersect.Intersection.BrepPlane(B[1], P, 0.001, out Csects2, out Psects);
                Vector3d[] Tangents = new Vector3d[2];
                ///Control Start Point of curve
                if ((Csects1[0].PointAtStart.X * P.Origin.X + Csects1[0].PointAtStart.Y * P.Origin.Y + Csects1[0].PointAtStart.Z * P.Origin.Z) < 0.00001) Csects1[0].Reverse();
                if ((Csects2[0].PointAtStart.X * P.Origin.X + Csects2[0].PointAtStart.Y * P.Origin.Y + Csects2[0].PointAtStart.Z * P.Origin.Z) < 0.00001) Csects2[0].Reverse();
                ///Get Tangent Vector
                Tangents[0] = (Csects1[0].PointAtNormalizedLength(0.05) - P.Origin);
                Tangents[0].Unitize();
                Tangents[1] = (Csects2[0].PointAtNormalizedLength(0.05) - P.Origin);
                Tangents[1].Unitize();
                Hare.Geometry.Vector[] HTangents = new Hare.Geometry.Vector[2] { new Hare.Geometry.Vector(Tangents[0].X, Tangents[0].Y, Tangents[0].Z), new Hare.Geometry.Vector(Tangents[1].X, Tangents[1].Y, Tangents[1].Z) };
                ///Get Normal
                double up, vp;
                ComponentIndex CI;
                Point3d outPt;
                Vector3d[] Normals = new Vector3d[2];
                //Point3d CPT = Utilities.PachTools.HPttoRPt(Z_mid);
                B[0].ClosestPoint(P.Origin, out outPt, out CI, out up, out vp, 0.01, out Normals[0]);
                B[1].ClosestPoint(P.Origin, out outPt, out CI, out up, out vp, 0.01, out Normals[1]);
                Hare.Geometry.Vector[] HNormals = new Hare.Geometry.Vector[2] { new Hare.Geometry.Vector(Normals[0].X, Normals[0].Y, Normals[0].Z), new Hare.Geometry.Vector(Normals[1].X, Normals[1].Y, Normals[1].Z) };
                //// Get Vector Tangents.
                //Hare.Geometry.Point Pt1 = new Hare.Geometry.Point(Pts[j-1].X, Pts[j-1].Y, Pts[j-1].Z);
                //Hare.Geometry.Point Pt2 = new Hare.Geometry.Point(Pts[j].X, Pts[j].Y, Pts[j].Z);
                double Delta_Z = Env_Props.Sound_Speed(P.Origin) / (4 * fs);//TODO: Adjust depending on distance from source to receiver... (nearest, farthest?)
                Sources.Add(new EdgeSource(Edge.Rigid, Utilities.PachTools.RPttoHPt(P.Origin), Delta_Z, HTangents));

                length += Delta_Z;
            }
        }