
! script name: macros.d/airfoil
! EXAMPLE: construct spline curve through Joukowski airfoil

!A
!A NAME:
!A
!A 	AIRFOIL
!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 be used as
!B 		the controlling length of the airfoil.
!B
!B 	A --- controls thickness of airfoil: Enter the value to be used
!B 		to determine the thickness of the airfoil.
!B
!B 	B --- controls curvature of airfoil: Enter the value to control
!B 		the curvature of the airfoil.
!B

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

DIM Answer$[256]
DIM Destination$[256]
DEG
! good parameters
L=5
A=.5
B=1
Theta=0

DeActivateUndo
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

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

Xcen=-A
Ycen=B
Zcen=0

Ang_inc=3
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
Sp=CSCurvePtGrp(Group,Pt,0,Pt,0)
Stat=DeleteGroup(Group)

Ang_inc=3
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
Sp=CSCurvePtGrp(Group,Pt,0,Pt,0)
Stat=DeleteGroup(Group)
GOTO Group_loop


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

