File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,13 @@ namespace RaysAndStuff
10
10
{
11
11
internal class Plane
12
12
{
13
+ public enum Halfspace
14
+ {
15
+ Halfspace_BEHIND , //behind the plane
16
+ Halfspace_ON_PLANE ,
17
+ Halfspace_FRONT , //in front of plane
18
+ } ;
19
+
13
20
public Plane ( Vector3 A , Vector3 B , Vector3 C )
14
21
{
15
22
Normal = Vector3 . Cross ( ( B - A ) , ( C - A ) ) ; // NORMAL = AB X AC
@@ -49,6 +56,14 @@ public float DistanceTo(Vector3 P)
49
56
return Vector3 . Dot ( Normal , P ) + D ;
50
57
}
51
58
59
+ public Halfspace ClassifyPoint ( Vector3 P )
60
+ {
61
+ float d = DistanceTo ( P ) ;
62
+ if ( d == 0 ) return Halfspace . Halfspace_ON_PLANE ;
63
+ if ( d > 0 ) return Halfspace . Halfspace_FRONT ;
64
+ return Halfspace . Halfspace_BEHIND ;
65
+ }
66
+
52
67
public readonly Vector3 Normal ; // Normalized vector perpendicular to the plane
53
68
public readonly float D ; // Distance from a point to the plane.
54
69
}
Original file line number Diff line number Diff line change 4
4
using System . Text ;
5
5
using System . Threading . Tasks ;
6
6
using System . Numerics ;
7
+ using System . Xml . Linq ;
7
8
8
9
namespace RaysAndStuff
9
10
{
10
11
internal struct Ray
11
12
{
12
13
public Vector3 Start ;
13
14
public Vector3 Dir ;
15
+ public override string ToString ( )
16
+ {
17
+ return "Start:" + Start . ToString ( ) + " Dir:" + Dir . ToString ( ) ;
18
+ }
14
19
}
15
20
}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public ShootRays()
21
21
for ( int r = 0 ; r < rays . Count ; r ++ )
22
22
{
23
23
Ray ray = rays [ r ] ;
24
+ Console . WriteLine ( $ "Ray { r } : { ray } ") ;
24
25
foreach ( Plane plane in planes )
25
26
{
26
27
if ( plane . RayIntersection ( ray . Start , ray . Dir , ref t , ref hitPt ) )
@@ -29,10 +30,13 @@ public ShootRays()
29
30
}
30
31
else
31
32
{
32
- Console . WriteLine ( "Ray missed plane " + count ) ;
33
+ Console . WriteLine ( $ "Ray { r } missed plane { count } " ) ;
33
34
}
34
35
float dist1 = plane . DistanceTo ( ray . Start ) ;
35
36
Console . WriteLine ( $ "Plane: { count } distance: { dist1 } ") ;
37
+ Plane . Halfspace halfspace = plane . ClassifyPoint ( ray . Start ) ;
38
+ var text = halfspace . ToString ( ) ;
39
+ Console . WriteLine ( "Classification Ray.start: " + text ) ;
36
40
count ++ ;
37
41
}
38
42
}
You can’t perform that action at this time.
0 commit comments