|
@@ -1,12 +1,8 @@
|
|
|
|
|
|
Namespace std.geom
|
|
Namespace std.geom
|
|
|
|
|
|
-#rem monkeydoc @hidden
|
|
|
|
-#end
|
|
|
|
Alias Planef:Plane<Float>
|
|
Alias Planef:Plane<Float>
|
|
|
|
|
|
-#rem monkeydoc @hidden
|
|
|
|
-#end
|
|
|
|
Struct Plane<T>
|
|
Struct Plane<T>
|
|
|
|
|
|
Field n:Vec3<T>
|
|
Field n:Vec3<T>
|
|
@@ -15,55 +11,53 @@ Struct Plane<T>
|
|
Method New()
|
|
Method New()
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method New( nx:Float,ny:Float,nz:Float,d:Float )
|
|
|
|
+ n.x=nx;n.y=ny;n.z=nz;Self.d=d
|
|
|
|
+ End
|
|
|
|
+
|
|
Method New( n:Vec3<T>,d:T )
|
|
Method New( n:Vec3<T>,d:T )
|
|
-
|
|
|
|
Self.n=n
|
|
Self.n=n
|
|
Self.d=d
|
|
Self.d=d
|
|
End
|
|
End
|
|
|
|
|
|
Method New( p:Vec3<T>,n:Vec3<T> )
|
|
Method New( p:Vec3<T>,n:Vec3<T> )
|
|
-
|
|
|
|
Self.n=n
|
|
Self.n=n
|
|
Self.d=-n.Dot( p )
|
|
Self.d=-n.Dot( p )
|
|
End
|
|
End
|
|
|
|
|
|
Method New( v0:Vec3<T>,v1:Vec3<T>,v2:Vec3<T> )
|
|
Method New( v0:Vec3<T>,v1:Vec3<T>,v2:Vec3<T> )
|
|
-
|
|
|
|
n=(v1-v0).Cross(v2-v0).Normalize()
|
|
n=(v1-v0).Cross(v2-v0).Normalize()
|
|
d=-n.Dot( v0 )
|
|
d=-n.Dot( v0 )
|
|
End
|
|
End
|
|
|
|
|
|
Operator-:Plane()
|
|
Operator-:Plane()
|
|
-
|
|
|
|
Return New Plane( -n,-d )
|
|
Return New Plane( -n,-d )
|
|
End
|
|
End
|
|
|
|
|
|
Method Distance:Double( p:Vec3<T> )
|
|
Method Distance:Double( p:Vec3<T> )
|
|
-
|
|
|
|
Return n.Dot( p )+d
|
|
Return n.Dot( p )+d
|
|
End
|
|
End
|
|
|
|
|
|
Method Nearest:Vec3<T>( p:Vec3<T> )
|
|
Method Nearest:Vec3<T>( p:Vec3<T> )
|
|
-
|
|
|
|
Return p-n*Distance( p )
|
|
Return p-n*Distance( p )
|
|
End
|
|
End
|
|
|
|
|
|
|
|
+ Method Normalize:Plane()
|
|
|
|
+ Local l:=n.Length
|
|
|
|
+ Return New Planef( n/l,d/l )
|
|
|
|
+ End
|
|
|
|
+
|
|
Method TIntersect:Double( line:Line<T> )
|
|
Method TIntersect:Double( line:Line<T> )
|
|
-
|
|
|
|
Return -Distance( line.o )/n.Dot( line.d )
|
|
Return -Distance( line.o )/n.Dot( line.d )
|
|
End
|
|
End
|
|
|
|
|
|
Method Intersect:Vec3<T>( line:Line<T> )
|
|
Method Intersect:Vec3<T>( line:Line<T> )
|
|
-
|
|
|
|
Return line * TIntersect( line )
|
|
Return line * TIntersect( line )
|
|
End
|
|
End
|
|
|
|
|
|
Method Intersect:Line<T>( p:Plane<T> )
|
|
Method Intersect:Line<T>( p:Plane<T> )
|
|
-
|
|
|
|
Local v:=n.Cross( p.n ).Normalize()
|
|
Local v:=n.Cross( p.n ).Normalize()
|
|
-
|
|
|
|
Local o:=p.Intersect( New Line<T>( n*-d,n.Cross( v ) ) )
|
|
Local o:=p.Intersect( New Line<T>( n*-d,n.Cross( v ) ) )
|
|
-
|
|
|
|
Return New Line<T>( o,v )
|
|
Return New Line<T>( o,v )
|
|
End
|
|
End
|
|
|
|
|