
! script name: 3dmacros.d/airfoilsurf
! EXAMPLE: construct a spline curve through a Joukowski airfoil

!A
!A NAME:
!A
!A 	Airfoil Surface
!A
!A DESCRIPTION:
!A
!A 	This script constructs a spline curve through a Joukowski airfoil.
!A
!B INSTRUCTIONS:
!B
!B 	L --- controls length of airfoil: Enter the value to control the length
!B 		of the airfoil.
!B
!B 	A --- controls thickness of airfoil: Enter the value to control the
!B 		thickness of the airfoil.
!B
!B 	B --- controls curvature of airfoil: Enter the value to control the
!B 		curvature of the airfoil.
!B
!C NOTE:
!C
!C 	The following are an example of good parameters:
!C 		L=5
!C 		A=0.5
!C 		B=1
!C 		ANGLE=0
!C

stat=ChangeLabelStr("ScriptNameStatus","Function: airfoil ")

DIM Answer$[256]
DIM Destination$[256]
DEG

ActivateUndo

L=5
A=.5
B=1
Theta=0

Group_loop:!

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(2*L)
L=GetValue("L --- controls length of airfoil ",Answer$)
IF (ExitScript(Destination$)) THEN Leave
L=L/2

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(A)
A=GetValue("A --- controls thickness of airfoil ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(B)
B=GetValue("B --- controls curvature of airfoil ",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Theta)
Theta=GetValue("ANGLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Surf_len)
Surf_len=GetValue("SURFACE LENGTH",Answer$)
IF (ExitScript(Destination$)) THEN Leave

Stat=SetInputFormat("n4=","")
Stat=SetEqualsValue(Twist_angle)
Twist_angle=GetValue("TWIST ANGLE",Answer$)
IF (ExitScript(Destination$)) THEN Leave

A1=L+A
R=SQR(A1*A1+B*B)

Xcen=-A
Ycen=B
Zcen=0

Ang_inc=10
Nsteps=ABS(180)/Ang_inc+1
Ang_inc=180/Nsteps

Group=CreateGroup("TEMPGROUP")
Pt_count=1

FOR I=0 TO Nsteps
	Ang=Astart+I*Ang_inc
	Cs=COS(Ang)
	Sn=SIN(Ang)

	X1=Xcen+R*Cs
	Y1=Ycen+R*Sn

	D1=(X1*X1+Y1*Y1)
	D1=L*L/D1

	X2=(1+D1)*X1
	Y2=(1-D1)*Y1

	X=X2*COS(Theta)+Y2*SIN(Theta)
	Y=-X2*SIN(Theta)+Y2*COS(Theta)

	Pt=PointXYZ(X,Y,Z)

	Stat=AddToGroup(Group,Pt)

	Pt_count=Pt_count+1
NEXT I


Pz=PointXYZ(0,0,Surf_len)
T1=AngleTransform(Pz,0,0,Twist_angle,WsWorkplaneVals)
G1=TransformGroup(Group,T1,"TEMP1")
Stat= CombineGroups(Group,G1)
Stat= DeleteEntity(G1)
Stat= DeleteEntity(Pz)

surf= GridSurface(WsCubicSurfEnt,Group,"CUBIC SURFACE",Pt_count-1,2)
Stat= DeleteGroup(Group)

Ang_inc=10
Nsteps=ABS(180)/Ang_inc+1
Ang_inc=180/Nsteps

Group=CreateGroup("TEMPGROUP")
Pt_count=1
FOR I=0 TO Nsteps
	Ang=Astart+180+I*Ang_inc
	Cs=COS(Ang)
	Sn=SIN(Ang)

	X1=Xcen+R*Cs
	Y1=Ycen+R*Sn

	D1=(X1*X1+Y1*Y1)
	D1=L*L/D1

	X2=(1+D1)*X1
	Y2=(1-D1)*Y1

	X=X2*COS(Theta)+Y2*SIN(Theta)
	Y=-X2*SIN(Theta)+Y2*COS(Theta)

	Pt=PointXYZ(X,Y,Z)

	Stat=AddToGroup(Group,Pt)

	Pt_count=Pt_count+1
NEXT I

G1=TransformGroup(Group,T1,"TEMP1")
Stat= CombineGroups(Group,G1)
Stat= DeleteEntity(G1)
Stat= DeleteEntity(Pz)
surf= GridSurface(WsCubicSurfEnt,Group,"CUBIC SURFACE",Pt_count-1,2)

ActivateUndo
Stat= AdvanceUndoNumber("cubic surf")
Stat= AddItemToUndo(WsUBCreateMode,Surf)

Stat=DeleteGroup(Group)
GOTO Group_loop


Leave:!
IF (NOT LEN(Destination$)) THEN
	 LOAD "typecontrol"
ELSE
	 LOAD Destination$
END IF
END

