public override CartesianList <Point> Visit(Line line) { CartesianList <Point> intersections = new CartesianList <Point>(); // this = 0 line = 1 // x = v0 + t0 * i0 = v1 + t1 * i1 // k0.dot(x) = k0.dot(v1) + t1 * k0.dot(i1) = k0.dot(v0) // k1.dot(x) = k1.dot(v0) + t0 * k1.dot(i0) = k1.dot(v1) // t0 = k1.dot(v1 - v0) / k1.dot(i0) // t1 = k0.dot(v0 - v1) / k0.dot(i1) double den0 = line.KHat.Dot(this.IHat); double den1 = this.KHat.Dot(line.IHat); if (System.Math.Abs(den0) > Constants.tol) { double t0 = line.KHat.Dot(line.Vertex - this.Vertex) / den0; double t1 = this.KHat.Dot(this.Vertex - line.Vertex) / den1; if (this.Contains(t0) && line.Contains(t1)) { intersections.Add(GetPoint(t0)); } } return(intersections); }
public override CartesianList <Point> Visit(Parabola parabola) { // points p on this parabola, p = t^2 / lr0 // points q on parabola, q = s^2 / lr1 // Debug.Log(string.Format("Oops! parabola parabola intersection not implemented")); CartesianList <Point> intersections = new CartesianList <Point>(); return(intersections); }
public override CartesianList <Point> Visit(Line line) { CartesianList <Point> intersections = new CartesianList <Point>(); List <double> solutions = new List <double>(); // p = v + x * ihat + z * khat // n.dot(p) = n.dot(p0) // n.dot(v + x*ihat + z*khat) = n.dot(p0) // n.dot(ihat) * x + n.dot(khat) * z = n.dot(p0) - n.dot(v) // a*x + b*z = c Vector n = line.KHat; double a = n.Dot(ihat); double b = n.Dot(khat); double c = n.Dot(line.Vertex - vertex); // z = x^2 / r // a*x + b*x^2/r = c // t^2 + (a*r/b)*t - c*r/b = 0 // t^2 + a*r/b*t + a^2*r^2/4*b^2 = a^2*r^2/4*b^2 + c*r/b // (t + a*r/2*b)^2 = (1/4*b^2)*(a^2*r^2 + 4*b*c*r) // t + a*r/2*b = +- sqrt(r*(a^2*r + 4*b*c)) / 2*b // t = (-a*r +- sqrt(r*(a^2*r + 4*b*c)) / 2*b double discriminant = latusRectum * (a * a * latusRectum + 4.0 * b * c); if (System.Math.Abs(b) > Constants.tol) { if (System.Math.Abs(discriminant) < Constants.tol) { double t = -0.5 * a * latusRectum / b; solutions.Add(t); } else if (discriminant > Constants.tol) { double sqrt = System.Math.Sqrt(discriminant); double t0 = -0.5 * (a * latusRectum - sqrt) / b; double t1 = -0.5 * (a * latusRectum + sqrt) / b; solutions.Add(t0); solutions.Add(t1); } else { // no solution } } else if (System.Math.Abs(a) > Constants.tol) { double t = c / a; solutions.Add(t); } foreach (double t in solutions) { if (this.Contains(t)) { Point p = GetPoint(t); if (line.Contains(p)) { intersections.Add(p); } } } return(intersections); }
public override CartesianList <Point> Visit(Parabola parabola) { CartesianList <Point> intersections = parabola.Visit(this); return(intersections); }
private void DeleteNodes(Site site, Node seed) { Tree <Node> deleted = new Tree <Node>(seed); Tree <Node> next = deleted.GetNext(); while (next != null) { Node node = next.Node; nodes.Remove(node); next.IsLeaf = true; List <Edge> edgeList = new List <Edge>(node.Edges); // save a copy to loop over so we can modify node.edges foreach (Edge e in edgeList) { Node other = e.OtherNode(node); if (other != null) { if (site.Distance(other.Point) < other.Clearance) { next.AddChild(other); } else { CartesianList <Point> intersections = new CartesianList <Point>(); foreach (Site side in e.Sites) { List <Curve> bisectors = side.GetBisectors(site); foreach (Curve b in bisectors) { CartesianList <Point> sideIntersection = e.Curve.Intersect(b); foreach (Point x in sideIntersection) { if (site.Influences(x) && side.Influences(x)) { intersections.AddNear(x); } } } } foreach (Point x in intersections) { Node newNode = AddNodeNear(x); if (newNode == other) { other.Connected = false; } else { new Edge(e.Left, e.Right, e.Curve, other, newNode, edgePrefab, cylinders); } } } e.RemoveFromNodes(); } } next = deleted.GetNext(); } }