1- using System . Collections . Generic ;
2-
1+
32namespace RadiantMapToWavefrontObj
43{
5- public class ClippingPlane
4+ public class ClippingPlane : Plane
65 {
7- public readonly double D ;
8- public readonly Vector Normal ;
9-
10- public double A => Normal . X ;
11- public double B => Normal . Y ;
12- public double C => Normal . Z ;
6+ public string Texture { get ; private set ; }
137
148 // Constructor for a clipping plane.
15- public ClippingPlane ( Vertex v1 , Vertex v2 , Vertex v3 )
9+ public ClippingPlane ( Vertex v1 , Vertex v2 , Vertex v3 , string texture ) : base ( v1 , v2 , v3 )
1610 {
17- Vector vector1 = new Vector ( v2 . X - v1 . X , v2 . Y - v1 . Y , v2 . Z - v1 . Z ) . Unit ( ) ;
18- Vector vector2 = new Vector ( v3 . X - v1 . X , v3 . Y - v1 . Y , v3 . Z - v1 . Z ) . Unit ( ) ;
19-
20- Normal = Vector . CrossProduct ( vector1 , vector2 ) . Unit ( ) ;
21- D = - ( A * v2 . X + B * v2 . Y + C * v2 . Z ) ;
11+ Texture = texture ;
2212 }
2313
24- // Returns the object as a string .
25- public override string ToString ( )
14+ // Set the texture of a clipping plane .
15+ public void SetTexture ( string texture )
2616 {
27- return "<" + A + ", " + B + ", " + C + ", " + D + ">" ;
17+ Texture = texture ;
2818 }
2919
3020 // Checks if three clipping planes intersect and if so, returns an intersection point.
31- public static bool FindIntersection ( ClippingPlane a , ClippingPlane b , ClippingPlane c , out Vertex intersection )
21+ public static bool FindIntersection ( Plane a , Plane b , Plane c , out Vertex intersection )
3222 {
3323 // Calculates the possible intersection point using the Cramer's rule.
3424 double det = Determinant ( a . A , a . B , a . C , b . A , b . B , b . C , c . A , c . B , c . C ) ;
@@ -38,28 +28,16 @@ public static bool FindIntersection(ClippingPlane a, ClippingPlane b, ClippingPl
3828 return false ;
3929 }
4030
41- double x = Determinant ( a . D , a . B , a . C , b . D , b . B , b . C , c . D , c . B , c . C ) / det ;
42- double y = Determinant ( a . A , a . D , a . C , b . A , b . D , b . C , c . A , c . D , c . C ) / det ;
43- double z = Determinant ( a . A , a . B , a . D , b . A , b . B , b . D , c . A , c . B , c . D ) / det ;
31+ double x = Determinant ( a . D , a . B , a . C , b . D , b . B , b . C , c . D , c . B , c . C ) / det ;
32+ double y = Determinant ( a . A , a . D , a . C , b . A , b . D , b . C , c . A , c . D , c . C ) / det ;
33+ double z = Determinant ( a . A , a . B , a . D , b . A , b . B , b . D , c . A , c . B , c . D ) / det ;
4434
4535 intersection = new Vertex ( x , y , z ) ;
4636 intersection . SetNormal ( ( a . Normal + b . Normal + c . Normal ) . Unit ( ) ) ;
4737
4838 return true ;
4939 }
5040
51- // Creates an array of all vertices that lie on this plane.
52- public Vertex [ ] FindVerticesInPlane ( Vertex [ ] vertices )
53- {
54- List < Vertex > res = new List < Vertex > ( ) ;
55- foreach ( Vertex v in vertices )
56- {
57- if ( v . OnPlane ( this ) )
58- res . Add ( v ) ;
59- }
60- return res . ToArray ( ) ;
61- }
62-
6341 // Calculates the determinant of a 2x2 matrix. (Can be done less verbose...)
6442 private static double Determinant ( double a11 , double a12 , double a21 , double a22 )
6543 {
0 commit comments