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; }
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; }
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); }
public static double DistToSegment(Vec2 p1, Vec2 p2, Vec2 pt) { return Maths.Dist(ClosestPointOnSegment(p1, p2, pt), pt); }
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)); }
/// <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); }
public static double AngleBetweenTwoPoints(Vec2 p1, Vec2 p2) { Vec2 p = p2 - p1; return Math.Atan2(p.y, p.x); }
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++; } }
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"; }
public RouteNode(Vec2 pos, double diameter, RouteElement parent) { Pos = pos; Diameter = diameter; Parent = parent; }