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

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

#2817:

  • Added line projection based bin packing
  • Added residual spaces to the view
File size: 1.8 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  /// <summary>
9  /// A line is given as a point and a directing vector
10  /// </summary>
11  internal class Line3D {
12    public Vector3D Point;
13    public Vector3D Direction;
14
15    public Line3D(Vector3D point, Vector3D direction) {
16      Point = point;
17      Direction = direction;
18    }
19    public Line3D(PackingPosition position, Vector3D direction) {
20      Point = new Vector3D(position);
21      Direction = direction;
22    }
23
24    public bool Intersects(Plane3D plane) {
25      return plane.Intersects(this);
26    }
27
28    public Vector3D Intersect(Plane3D plane) {
29      return plane.Intersect(this);
30    }
31
32    public Vector3D Intersect(Line3D line) {
33      double r = 0;
34      double s = 0;
35
36      if (Direction.X != 0) {
37        r = (line.Point.X - this.Point.X) / (double)Direction.X;
38      } else if (Direction.Y != 0) {
39        r = (line.Point.Y - this.Point.Y) / (double)Direction.Y;
40      } else if (Direction.Z != 0) {
41        r = (line.Point.Z - this.Point.Z) / (double)Direction.Z;
42      }
43
44      if (line.Direction.X != 0) {
45        s = (this.Point.X - line.Point.X) / (double)line.Direction.X;
46      } else if (line.Direction.Y != 0) {
47        s = (this.Point.Y - line.Point.Y) / (double)line.Direction.Y;
48      } else if (line.Direction.Z != 0) {
49        s = (this.Point.Z - line.Point.Z) / (double)line.Direction.Z;
50      }
51
52      var a = r * this.Direction + this.Point;
53      var b = s * line.Direction + line.Point;
54      var c = a.Equals(b);
55      if (s!=0 && r!=0 && a.Equals(b)) {
56       
57        return a;
58      }
59
60      return null;
61    }
62  }
63}
Note: See TracBrowser for help on using the repository browser.