TrdMCClusterR Fit Classifier
test_code.h
Go to the documentation of this file.
1 
2 //---------------------------------------------------------------------------------------------------
3 bool do3DLinesIntersect(const std::vector<Line::FitLine2D>& linesA, const std::vector<Line::FitLine2D>& linesB) {
4  std::vector<Vector3D> intersectionPointsA;
5  std::vector<Vector3D> intersectionPointsB;
6 
7  // 1. Check intersections in 2D
8  for (size_t i = 0; i < 3; ++i) {
9  IntersectionResult res = findIntersection(linesA[i], linesB[i]);
10 
11  if (!res.intersects && !res.areCoincident) return false;
12 
13  // Convert 2D intersection points into 3D
14  if (i == 0) { // XY plane
15  intersectionPointsA.push_back(Vector3D(res.point.x, res.point.y, 0));
16  intersectionPointsB.push_back(Vector3D(res.point.x, res.point.y, 0));
17  } else if (i == 1) { // XZ plane
18  intersectionPointsA.push_back(Vector3D(res.point.x, 0, res.point.y));
19  intersectionPointsB.push_back(Vector3D(res.point.x, 0, res.point.y));
20  } else { // YZ plane
21  intersectionPointsA.push_back(Vector3D(0, res.point.x, res.point.y));
22  intersectionPointsB.push_back(Vector3D(0, res.point.x, res.point.y));
23  }
24  }
25 
26  // 2. Measure distance between 3D intersection points
27  for (size_t i = 0; i < 3; ++i) {
28  double dist = distance3D(intersectionPointsA[i], intersectionPointsB[i]);
29  if (dist > INTERSECTION_DISTANCE_THRESHOLD) return false;
30  }
31 
32  // 3. Convert FitLine2D to 3D lines (you might already have a method for this)
33  Line3D line3DA = convertTo3DLine(linesA);
34  Line3D line3DB = convertTo3DLine(linesB);
35 
36  // 4. Calculate perpendicular distance between 3D lines
37  double perpendicularDistance = distanceBetween3DLines(line3DA, line3DB);
38  return perpendicularDistance <= PERPENDICULAR_DISTANCE_THRESHOLD;
39 }
40 
41 double distance3D(const Vector3D& a, const Vector3D& b) {
42  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y) + (a.z - b.z) * (a.z - b.z));
43 }
44 
45 double distanceBetween3DLines(const Line3D& lineA, const Line3D& lineB) {
46  // This function calculates the shortest distance between two 3D lines.
47  // Please refer to any 3D geometry resource for a formula on how to achieve this.
48  // The formula is a bit involved but standard in computational geometry.
49 
50  // ... [code to compute distance]
51 
52  return distance;
53 }
54 //---------------------------------------------------------------------------------------------------
Definition: Line3DCompare.h:6
double x
Definition: Line3DCompare.h:7
double z
Definition: Line3DCompare.h:7
double y
Definition: Line3DCompare.h:7
double distance3D(const Vector3D &a, const Vector3D &b)
Definition: test_code.h:41
double distanceBetween3DLines(const Line3D &lineA, const Line3D &lineB)
Definition: test_code.h:45
bool do3DLinesIntersect(const std::vector< Line::FitLine2D > &linesA, const std::vector< Line::FitLine2D > &linesB)
Definition: test_code.h:3