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

Last change on this file was 15617, checked in by rhanghof, 23 months ago

#2817:

  • The items can be rotated and tilted now.
  • Added pruning of extreme points in packed bins.
  • Added new packer which packs items by positioning them on the point with the minimum of wasted space. He uses rotating and tilting of items.
  • Added classes for sorting given items.
File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.Threading.Tasks;
27
28namespace HeuristicLab.Problems.BinPacking3D.Geometry {
29  /// <summary>
30  /// A line is given as a point and a directing vector
31  /// </summary>
32  public class Line3D {
33    public Vector3D Point;
34    public Vector3D Direction;
35
36    public Line3D(Vector3D point, Vector3D direction) {
37      Point = point;
38      Direction = direction;
39    }
40    public Line3D(PackingPosition position, Vector3D direction) {
41      Point = new Vector3D(position);
42      Direction = direction;
43    }
44
45    public bool Intersects(Plane3D plane) {
46      return plane.Intersects(this);
47    }
48
49    public Vector3D Intersect(Plane3D plane) {
50      return plane.Intersect(this);
51    }
52
53    /// <summary>
54    /// Returns the intersection point of two lines.
55    /// It the lines doesn't intersect it returns null.
56    /// </summary>
57    /// <param name="line"></param>
58    /// <returns></returns>
59    public Vector3D Intersect(Line3D line) {
60      double r = 0;
61      double s = 0;
62
63      // if they have the same source point, this point can be returned.
64      if (this.Point.Equals(line.Point)) {
65        return this.Point;
66      }
67
68      if (Direction.X != 0) {
69        r = (line.Point.X - this.Point.X) / (double)Direction.X;
70      } else if (Direction.Y != 0) {
71        r = (line.Point.Y - this.Point.Y) / (double)Direction.Y;
72      } else if (Direction.Z != 0) {
73        r = (line.Point.Z - this.Point.Z) / (double)Direction.Z;
74      }
75
76      if (line.Direction.X != 0) {
77        s = (this.Point.X - line.Point.X) / (double)line.Direction.X;
78      } else if (line.Direction.Y != 0) {
79        s = (this.Point.Y - line.Point.Y) / (double)line.Direction.Y;
80      } else if (line.Direction.Z != 0) {
81        s = (this.Point.Z - line.Point.Z) / (double)line.Direction.Z;
82      }
83      var p1 = r * this.Direction + this.Point;
84      var p2 = s * line.Direction + line.Point;
85      var c = p1.Equals(p2);
86      if (s!=0 && r!=0 && p1.Equals(p2)) {       
87        return p1;
88      }
89
90      return null;
91    }
92  }
93}
Note: See TracBrowser for help on using the repository browser.