public Intersection intersectsObject(Trace trace, Object3d o3dWithThisBorder) { PlaneBorder aBorder = this; if (trace.traceline.direction.dotProduct(aBorder.getNormal()) == 0) { return(Intersection.notIntersect(o3dWithThisBorder)); //trace is parallel to plane, will not intersect. } Scientrace.Location intersectLoc = aBorder.intersectsAt(trace.traceline); if (intersectLoc == null) { return(Intersection.notIntersect(o3dWithThisBorder)); //trace is parallel to plane, will not intersect. } return(new Intersection(true, o3dWithThisBorder, intersectLoc, new Scientrace.FlatShape2d(this.tPlane), null, this.contains(trace.traceline.startingpoint))); }
} //end string exportX3D(env) public override Intersection intersects(Trace aTrace) { // Finding intersectionpoints at spheres Scientrace.Intersection sphere1Intersections = this.dummySphere1.intersects(aTrace); Scientrace.Intersection sphere2Intersections = this.dummySphere2.intersects(aTrace); /* No sphere intersections at all? */ if (!sphere1Intersections.intersects && !sphere2Intersections.intersects) { return(Intersection.notIntersect(this)); } List <IntersectionPoint> iplist = new List <IntersectionPoint>(); //conditional &&'s, locations are only probed if existing if ((sphere1Intersections.enter != null) && this.dummySphere2.contains(sphere1Intersections.enter.loc)) { iplist.Add(sphere1Intersections.enter); } if ((sphere1Intersections.exit != null) && this.dummySphere2.contains(sphere1Intersections.exit.loc)) { iplist.Add(sphere1Intersections.exit); } if ((sphere2Intersections.enter != null) && this.dummySphere1.contains(sphere2Intersections.enter.loc)) { iplist.Add(sphere2Intersections.enter); } if ((sphere2Intersections.exit != null) && this.dummySphere1.contains(sphere2Intersections.exit.loc)) { iplist.Add(sphere2Intersections.exit); } /* No valid intersections? */ if (iplist.Count < 1) { return(Intersection.notIntersect(this)); } Scientrace.IntersectionPoint[] ips = iplist.ToArray(); Scientrace.Intersection lensIntersection = new Scientrace.Intersection(aTrace, ips, this); // when currently inside the lens, intersection from here must mean leaving. lensIntersection.leaving = this.contains(aTrace.traceline.startingpoint); //return created new intersection return(lensIntersection); }
public override Intersection intersects(Scientrace.Trace aTrace) { // Finding intersectionpoints at sphere Scientrace.Intersection sphereIntersections = this.dummySphere.intersects(aTrace); /* If the PlanoConvexLens doesn't even pass the surface of the sphere, the intersection * of the lens does not exist. */ if (!sphereIntersections.intersects) { //return sphereIntersections; return(Intersection.notIntersect(this)); } Scientrace.Location planoLoc = this.lensPlane.lineThroughPlane(aTrace.traceline); Scientrace.IntersectionPoint planoIP; if ((!this.dummySphere.contains(planoLoc)) || (planoLoc == null)) { planoIP = null; } else { planoIP = new Scientrace.IntersectionPoint(planoLoc, this.lensPlane.planeToFlatShape2d()); } Scientrace.IntersectionPoint[] ips = new Scientrace.IntersectionPoint[3]; ips[0] = planoIP; ips[1] = this.lensPlane.filterOutsideBorder(sphereIntersections.enter); ips[2] = this.lensPlane.filterOutsideBorder(sphereIntersections.exit); Scientrace.Intersection lensIntersection = new Scientrace.Intersection(aTrace, ips, this); // when currently inside the lens, intersection from here must mean leaving. lensIntersection.leaving = this.contains(aTrace.traceline.startingpoint); //return created new intersection return(lensIntersection); }
public override Intersection intersects(Trace aTrace) { /* OK, this is how we are going to do this: * First (1), we find all intersectionpoints for all sub-borders and order them * as a function of the distance from the startingpoint of the trace. Then (2), we * take the average location in between two consecutive intersectionpoints. Let's * ask all SubVolumes if anybody has this average value in it's body (3). We will * repeat this procedure until we find an average value that is *NOT* included (4). The * very first intersectionpoint, and the last intersectionpoint before that latest * assessed average will be the two intersectionpoints construction the Intersection (5) * value to return. * A final remark must be made: when a trace is leaving from the current object and the * average location between the start of the trace and the first intersection is also * within the object, the first intersectionpoint is actually virtual and should be * removed. (6) */ // (1) // create an orderedlist with as keys the distances from the last intersection to this ip SortedList <double, IntersectionPoint> all_ips = new SortedList <double, IntersectionPoint>(); Scientrace.Location subTraceStart = aTrace.traceline.startingpoint; foreach (PlaneBorderEnclosedVolume aSubVolume in subVolumes) { Intersection tIntersection = aSubVolume.intersects(aTrace); if (tIntersection.intersects) { this.conditionalIPList(all_ips, tIntersection, subTraceStart); } } IntersectionPoint previous_ip = null; IntersectionPoint first_ip = null; IntersectionPoint last_ip = null; for (int iKey = 0; iKey < all_ips.Keys.Count; iKey++) { double currentKey = all_ips.Keys[iKey]; IntersectionPoint currentIP = all_ips[currentKey]; if (previous_ip == null) { // is this the last IP in the list? if (iKey != all_ips.Count - 1) { // If both the area between the start of the trace and that between this and the next trace is contained, skip to the next (by continue) IntersectionPoint nextIP = all_ips[all_ips.Keys[iKey + 1]]; if (this.contains(subTraceStart.avgWith(currentIP.loc)) && this.contains(currentIP.loc.avgWith(nextIP.loc))) { continue; } } // (6) if (this.contains(subTraceStart.avgWith(currentIP.loc)) && (iKey + 1 != all_ips.Keys.Count)) { first_ip = currentIP; break; } else { // the first ip in the list, no average to take with previous value first_ip = currentIP; } } else { // (2) Scientrace.Location average_loc = currentIP.loc.avgWith(previous_ip.loc); // (3) if (!this.contains(average_loc)) { //Console.WriteLine("BREAKOUT!!!!"); last_ip = previous_ip; // (4) Break out of foreach loop, we've found the last point in this intersection (the previous one in the list) break; } } // last statement in foreach loop, defining the current IP als the previous for the next cycle. previous_ip = currentIP; } // there has to be at least ONE intersection to succeed... if (first_ip == null) { return(Intersection.notIntersect(this)); } /* below must be the most obscure line in this routine, sry about that. * it does this: if last_ip is still unassigned, assign previous_ip as long as it differs from first_ip... */ // last_ip = last_ip ?? (previous_ip != first_ip ? previous_ip : null); if (last_ip == null) { last_ip = (previous_ip != first_ip ? previous_ip : null); } // (5) Scientrace.IntersectionPoint[] real_ips = new Scientrace.IntersectionPoint[2]; real_ips[0] = first_ip; real_ips[1] = last_ip; Intersection retIntersect = new Intersection(aTrace, real_ips, this); return(retIntersect); //end func. intersect }