[go: up one dir, main page]

File: Plane.py

package info (click to toggle)
uranium 3.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,876 kB
  • sloc: python: 22,349; sh: 111; makefile: 11
file content (40 lines) | stat: -rw-r--r-- 972 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (c) 2015 Ultimaker B.V.
# Uranium is released under the terms of the LGPLv3 or higher.

from UM.Math.Vector import Vector
from UM.Math.Float import Float


##      Plane representation using normal and distance.
class Plane:
    def __init__(self, normal = Vector(), distance = 0.0):
        super().__init__()

        self._normal = normal
        self._distance = distance

    @property
    def normal(self):
        return self._normal

    @property
    def distance(self):
        return self._distance

    def intersectsRay(self, ray):
        w = ray.origin - (self._normal * self._distance)

        nDotR = self._normal.dot(ray.direction)
        nDotW = -self._normal.dot(w)

        if Float.fuzzyCompare(nDotR, 0.0):
            return False

        t = nDotW / nDotR
        if t < 0:
            return False

        return t

    def __repr__(self):
        return "Plane(normal = {0}, distance = {1})".format(self._normal, self._distance)