Esempio n. 1
0
        public static Vec2 ClosestPointOnSegment(Vec2 p1, Vec2 p2, Vec2 pt)
        {
            Vec2 length = p2 - p1;
            double l2 = length.Abs();

            if (l2 == 0) return p1;

            double t = Vec2.ScalarProduct(pt - p1, length) / l2;

            if (t < 0) return p1;
            if (t > 1) return p2;
            return p1 + t * length;
        }
Esempio n. 2
0
        public Arc(Vec2 center, Vec2 start, Vec2 end, double diameter, double width, string layer, string net)
        {
            Net = net;
            Layer = new string[] { layer };

            Nodes = new RouteNode[2];
            Nodes[0] = new RouteNode(start, width, this);
            Nodes[1] = new RouteNode(end, width, this);
            Type = "ARC";

            double angle;
            double aStart = (end - center).Angle();
            double aEnd = (start - center).Angle();
            if (aEnd < aStart) angle = (Math.PI * 2.0 - aStart) + aEnd;
            else angle = aEnd - aStart;

            Length = angle * diameter / 2;
        }
Esempio n. 3
0
 public static double AngleBetween(Vec2 a, Vec2 b)
 {
     double dotProd = ScalarProduct(a, b);
     double lenProd = a.Abs() * b.Abs();
     double divOperation = dotProd / lenProd;
     return Math.Acos(divOperation);
 }
Esempio n. 4
0
 public static double DistToSegment(Vec2 p1, Vec2 p2, Vec2 pt)
 {
     return Maths.Dist(ClosestPointOnSegment(p1, p2, pt), pt);
 }
Esempio n. 5
0
 public static double Dist(Vec2 p1, Vec2 p2)
 {
     return Math.Sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
 }
Esempio n. 6
0
 /// <summary>
 /// Returns the scalar product of p1 and p2
 /// </summary>
 /// <param name="p1"></param>
 /// <param name="p2"></param>
 /// <returns></returns>
 public static double ScalarProduct(Vec2 p1, Vec2 p2)
 {
     return (p1.x * p2.x + p1.y * p2.y);
 }
Esempio n. 7
0
 public static double AngleBetweenTwoPoints(Vec2 p1, Vec2 p2)
 {
     Vec2 p = p2 - p1;
     return Math.Atan2(p.y, p.x);
 }
Esempio n. 8
0
        public Via(Dictionary<string, PadStack> PadStacks, Vec2 pos, string padstack, string net)
        {
            Net = net;
            PadStack ps = PadStacks[padstack];
            Layer = new string[ps.PadInfo.Count];
            Nodes = new RouteNode[ps.PadInfo.Count];
            Type = "VIA";

            int i = 0;
            foreach (KeyValuePair<string, PadStack.PadStackLayerDef> def in ps.PadInfo)
            {
                Layer[i] = def.Key;
                Nodes[i] = new RouteNode(pos, Math.Min(def.Value.sx, def.Value.sy), this);
                i++;
            }
        }
Esempio n. 9
0
 public Segment(Vec2 p1, Vec2 p2, double width, string layer, string net)
 {
     Net = net;
     Layer = new string[] { layer };
     Nodes = new RouteNode[2];
     Nodes[0] = new RouteNode(p1, width, this);
     Nodes[1] = new RouteNode(p2, width, this);
     Length = Maths.Dist(Nodes[0].Pos, Nodes[1].Pos);
     Type = "TRACK";
 }
Esempio n. 10
0
 public RouteNode(Vec2 pos, double diameter, RouteElement parent)
 {
     Pos = pos;
     Diameter = diameter;
     Parent = parent;
 }