예제 #1
0
        public static KeyValuePair <Rational, double>[] PointGist(PointProjectionSolver solver)
        {
            var result   = new Dictionary <Rational, double>();
            var segments = GetSegments(solver);
            var vectors  = GetVectors(solver, segments);

            foreach (var vector in vectors)
            {
                foreach (var segment in segments)
                {
                    var d = segment.Distance2To(vector);
                    if (d == 0 || d == 1)
                    {
                        continue;
                    }
                    if (!Arithmetic.IsSquare(d))
                    {
                        continue;
                    }

                    d = Arithmetic.Sqrt(d);
                    d = d.Reduce();
                    //if (d.Numerator != 1)
                    //    continue;

                    if (!result.ContainsKey(d))
                    {
                        result[d] = 0;
                    }
                    result[d] += segment.IrrationalLength;
                }
            }
            return(result.OrderByDescending(p => p.Value).Take(3).ToArray());
        }
예제 #2
0
 private static Segment[] GetSegments(PointProjectionSolver solver)
 {
     return(solver.spec.Segments);
     //return solver.AllSegments
     //    .Where(s => Arithmetic.IsSquare(s.QuadratOfLength))
     //    .ToArray();
 }
예제 #3
0
        public static Rational?GetRibbonWidth(PointProjectionSolver solver)
        {
            double percent;
            var    pointGist    = PointGist(solver);
            var    parallelGist = ParallelGist(solver, out percent);

            return(Indicate(pointGist, parallelGist, percent));
        }
예제 #4
0
        private static HashSet <Vector> GetVectors(PointProjectionSolver solver, Segment[] segments)
        {
            var vectors = new HashSet <Vector>();

            foreach (var segment in segments)
            {
                vectors.Add(segment.Start);
                vectors.Add(segment.End);
            }
            return(vectors);
        }
예제 #5
0
        public static KeyValuePair <Rational, double>[] ParallelGist(PointProjectionSolver solver, out double hasParallelFactor)
        {
            var result           = new Dictionary <Rational, double>();
            var segments         = GetSegments(solver);
            var hasParallelCount = 0;

            foreach (var s1 in segments)
            {
                bool hasParallel = false;
                foreach (var s2 in segments)
                {
                    var sd = Arithmetic.InDistance2(s1.Start, s2);
                    var ed = Arithmetic.InDistance2(s1.End, s2);

                    if (sd.HasValue && ed.HasValue)
                    {
                        if (sd.Value == ed.Value)
                        {
                            var d = sd.Value;
                            if (d == 0 || d == 1)
                            {
                                continue;
                            }
                            if (!Arithmetic.IsSquare(d))
                            {
                                continue;
                            }

                            d = Arithmetic.Sqrt(d);
                            d = d.Reduce();
                            if (!result.ContainsKey(d))
                            {
                                result[d] = 0;
                            }
                            result[d]++;
                            if (!hasParallel)
                            {
                                hasParallelCount++;
                                hasParallel = true;
                            }
                        }
                    }
                }
            }
            hasParallelFactor = ((double)hasParallelCount) / segments.Length;
            return(result.OrderByDescending(p => p.Value).Take(3).ToArray());
        }