source: branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Geometry/Edge3D.cs @ 15520

Last change on this file since 15520 was 15520, checked in by rhanghof, 22 months ago

#2817:

  • Changed the calculation algorithm for creating extreme points by using line based projection
  • Changed the calculation of the residual spaces for line based projection
File size: 2.4 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Problems.BinPacking3D.Geometry {
8  public class Edge3D {
9    public Edge3D() { }
10
11    public Edge3D(PackingPosition start, PackingPosition end) {
12      Start = new Vector3D(start);
13      End = new Vector3D(end);
14    }
15
16    public Edge3D(Vector3D start, Vector3D end) {
17      Start = start;
18      End = end;
19    }
20
21    public Vector3D Start { get; set; }
22    public Vector3D End { get; set; }
23
24
25   
26
27    /// <summary>
28    /// Returns true if a given point lies on the edge.
29    /// </summary>
30    /// <param name="point"></param>
31    /// <returns>Returns true if a given point lies on the edge.</returns>
32    public bool LiesOn(Vector3D point) {
33      if (point == null) {
34        return false;
35      }
36      var x = (Start.X <= point.X && point.X <= End.X) || (Start.X >= point.X && point.X >= End.X);
37      var y = (Start.Y <= point.Y && point.Y <= End.Y) || (Start.Y >= point.Y && point.Y >= End.Y);
38      var z = (Start.Z <= point.Z && point.Z <= End.Z) || (Start.Z >= point.Z && point.Z >= End.Z);
39      return x && y && z;
40    }
41
42
43    /// <summary>
44    /// Returns a point where the two edges intersects.
45    /// It returns null if they don't intersect.
46    /// </summary>
47    /// <param name="edge"></param>
48    /// <returns>Returns a point where the two edges intersects. Null = no intersection.</returns>
49    public Vector3D Intersects(Edge3D edge) {
50      return Intersects(this, edge);
51    }
52
53    /// <summary>
54    /// Returns a point where two edges are intersecting.
55    /// It returns null if they don't intersect.
56    /// </summary>
57    /// <param name="e1"></param>
58    /// <param name="e2"></param>
59    /// <returns>Returns a point where the two edges intersects. Null = no intersection.</returns>
60    public static Vector3D Intersects(Edge3D e1, Edge3D e2) {
61      Line3D l1 = new Line3D(e1.Start, new Vector3D() {
62        X = e1.Start.X - e1.End.X,
63        Y = e1.Start.Y - e1.End.Y,
64        Z = e1.Start.Z - e1.End.Z
65      });
66      Line3D l2 = new Line3D(e2.Start, new Vector3D() {
67        X = e2.Start.X - e2.End.X,
68        Y = e2.Start.Y - e2.End.Y,
69        Z = e2.Start.Z - e2.End.Z
70      });
71      Vector3D point = l1.Intersect(l2);
72      if (e1.LiesOn(point) && e2.LiesOn(point)) {
73        return point;
74      }
75      return null;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.