
! script name: 3dintersect.d/fastintsurfs
! 3dtopic: fast intersection of two surfaces

!A
!A NAME:
!A
!A 	Fast Intersect Surfaces
!A
!A DESCRIPTION:
!A
!A 	This script will generate the path of intersection of two surfaces
!A	using a fast algorithm.
!A
!B INSTRUCTIONS:
!B
!B 	TOLERANCE: Enter the amount of variation allowed.
!B
!B 	PICK SURFACE #1: Pick one of the two surfaces to be used for the
!B 		intersection. Pick location may affect curve generated.
!B
!B 	PICK SURFACE #2: Pick the other surface to be used for the 
!B		intersection.  Pick location may affect curve generated.
!B
!C  NOTES:
!C
!C 	The fast intersect is mathematically the same as the regular intersect.
!C
!C 	The fast intersect is fast because it uses the pick locations and it
!C 	does not search as exhaustively for all possible intersections.
!C 	The extent of the search is controlled by the patch density
!C 	and the plot density of the surface.
!C
!C 	The fast trim may fail to find all intersections. This method may
!C 	fail if at least one of the surfaces has many small radii through
!C 	which the intersect curve must propagate.
!C
!C 	If this method fails increasing the plot density on one or both
!C 	surfaces forces a more exhaustive search.
!C
!C	The intersect curve generated in such a way as to propagate
!C	in the same direction as the u-curves in the first surface picked.
!C	This is done to insure consistant generation for vdm.
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: fast intersect surfaces ")

DIM Destination$[256]
DIM Answer$[256]
DIM Surface_dir$[80]


ActivateUndo
Tol=NamedVarVal("3D Intersect Tol",Ws3DSystemVars,0.005)


Start:!
StdWorkplane

stat= Setup3dCutter(WsNullTool,0.0,0.0,0.0,0.0,0.0)
Intersect2:StdWorkplane

Pick_loop:!

Stat= SetPickMask(WsPickSurfOnly)
stat= SetInputFormat("n0","")
Surface1=PickEntity("PICK SURFACE #1",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Surface1) THEN Pick_loop

UVpoint1= LastUVSurfPick(Surface1)
IF NOT ValidGeometry(UVpoint1) THEN Pick_loop
U= XPointValue(UVpoint1)
V= YPointValue(UVpoint1)

Pick_surf2:!
Stat= SetPickMask(WsPickSurfOnly)
Surface2=PickEntity("PICK SURFACE #2",Answer$)
IF (ExitScript(Destination$)) THEN Leave
IF NOT ValidGeometry(Surface2) THEN Pick_surf2

UVpoint2= LastUVSurfPick(Surface2)
IF NOT ValidGeometry(UVpoint2) THEN Pick_surf2
U= XPointValue(UVpoint2)
V= YPointValue(UVpoint2)

Stat= SetPickMask(WsPickGeometry)

Normal_sign1= 1
Normal_sign2= 1

Path_group= FastIntSurfs(Surface1,Normal_sign1,UVpoint1,Surface2,Normal_sign2,UVpoint2,Tol)

ActivateUndo
Stat= AdvanceUndoNumber("intersect curve")
Stat= AddGroupToUndo(WsUBCreateMode,Path_group,0,WsTrue)

stat= DeleteEntity(Path_group)
stat= DeleteEntity(UVpoint1)
stat= DeleteEntity(UVpoint2)

GOTO Intersect2


Leave:!
stat= SetInputFormat("n4","")
Stat= SetPickMask(WsPickGeometry)
stat= DeleteEntity(UVpoint1)
stat= DeleteEntity(UVpoint2)
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END
