GC Script Sun Vector

In 2010 Eike Schling translated a VB script of the sun vector- by David Kosdruy – to GCScript for Generative Components. The Script is attached below. This routine is very helpful for generating singular, single or double arrays of the sun vector. The code was used for several projects and competition an PLP Architecture.

 

// Bentley GenerativeComponents Transaction File — File structure version 1.08. (Please do not delete or change this line.)

environment
{
GCVersion = ‘08.11.08.260’;
MSVersion = ‘08.11.07.443’;
MSProject = ‘GC_Default’;
MSDesignFile = ‘C:\Users\Eike\Dropbox\11_Blog\110601-GC SunScript\130305-SUN.dgn’;
}

transaction graphChange ‘VAR (london)’
{
feature User.Objects.Radius Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 1;
RangeMinimum = 0.1;
RangeStepSize = 0.05;
Value = 10;
}
feature User.Objects.Timezone Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 12.0;
RangeMinimum = -12.0;
RangeStepSize = 1.0;
Value = 0;
}
feature User.Objects.Latitude Bentley.GC.Features.GraphVariable
{
RangeMaximum = 360.0;
Value = 50.517;
}
feature User.Objects.Longitude Bentley.GC.Features.GraphVariable
{
RangeMaximum = 360.0;
Value = 00.106;
}
feature User.Objects.Hour Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 24.0;
RangeStepSize = 0;
Value = 12.0;
}
feature User.Objects.Day Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 31.0;
RangeStepSize = 1.0;
Value = 21.0;
}
feature User.Objects.Month Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 12.0;
RangeStepSize = 1.0;
Value = 8.0;
}
feature User.Objects.Year Bentley.GC.Features.GraphVariable
{
LimitValueToRange = true;
RangeMaximum = 2050.0;
RangeMinimum = 2000.0;
RangeStepSize = 1.0;
Value = 2013.0;
}
}

transaction graphChange ‘Add SUN’
{
feature User.Objects.SUN Bentley.GC.Features.Line
{
Function = function (CoordinateSystem CS,
double year,
double month,
double day,
double hour,
double timezone,
double latitude,
double longitude,
)
{
/* jd = julianische Tageszahl
jd0 = julianische Tageszahl um 0 Uhr
n = Zeitvariable (seit 01.01.2000,12 Uhr)
L = mittlere ekliptikale Laenge
g = mittlere Anomalie
divisor =[
lambda, epsilon, alpha, delta
Dim t0, thetaHG, thetaG, theta, tau
Dim denominator, A, alt
Dim i

‘Dim for Geometry

Dim azX, azY, altZ, dis, tempDis
Dim arrStart,arrEnd*/
Line SUN = {};
for (int i = 0; i < 12; ++i)
{SUN[i] = {};

for (int j = 0; j < 24; ++j)
{
month = i;
hour = j;
SUN[i][j] = {};

int jdDay = (365.25 * (year + 4716)) + (30.6001 * (month + 1)) + day – 1524.5 – 14;
double jd0 = jdDay+0.5;
double Daytime =(hour-timezone)/24;
double jd = jd0 + (hour-timezone)/24;
double n = jd – 2451545.0;
double L = 280.460 + 0.9856474 * n;
double g = 357.528 + 0.9856003 * n;

if (L>360)
{ int divisorL = (L/360);
L = L – (360 * divisorL);
if (L<0)
{ L=L+360;}
}

if (g>360)
{int divisorg = (g/360);
g = g – (360 * divisorg);
if (g<0)
{g=g+360;}
}

double lambda = L + 1.915 * Sin(g) + 0.020 * Sin(2*g);
double epsilon = 23.439 – 0.0000004 * n;
double alpha = Atan((Cos(epsilon) * Sin(lambda)) / Cos(lambda));

if (Cos(lambda)<0)
{alpha = alpha + 180;}

double delta = Asin(Sin(epsilon) * Sin(lambda));

//AZIMUT
double t0 = (jd0 – 2451545.0) / 36525;
double thetaHG = 6.697376 + 2400.05134 * t0 + 1.002738 * (hour-timezone);

if (thetaHG > 24)
{
int divisor = (thetaHG/24);
thetaHG = thetaHG – (divisor * 24);
}

double thetaG = thetaHG * 15;
double theta = thetaG + longitude;
double tau = theta – alpha;
double denominator = (Cos(tau) * Sin(latitude))-(Tan(delta) * Cos(latitude));

// A = Azimuth, alt = Altitude;
double A = Atan(Sin(tau)/((Cos(tau) * Sin(latitude))-(Tan(delta) * Cos(latitude))));
if (denominator < 0)
{A = A + 180;}
double alt = Asin(Cos(delta) * Cos(tau) * Cos(latitude) + Sin(delta) * Sin(latitude));

//GEOMETRY
Point ptVert = new Point();
ptVert.ByDirectionAndDistanceFromOrigin(CS,CS.ZDirection,10);
Arc arcBase = new Arc();
arcBase.ByCenterRadiusSweepAngle(CS,CS.XYPlane,10,A,-90);
Arc arcAlt = new Arc();
arcAlt.ByAngleCenterStartPlanePoint(CS,arcBase.EndPoint,ptVert,alt);

//ALL SUNRAYS VISIBLE+INVISIBLE
SUN[i][j] = new Line(this);
SUN[i][j].ByPoints(arcAlt.EndPoint,CS);

/*
//SUNRAYS VISIBLE ABOVE HORIZON
if (arcAlt.EndPoint.Z>0)
{
SUN[i][j] = new Line(this);
SUN[i][j].ByPoints(arcAlt.EndPoint,CS);
}*/

}
}
return SUN;
};
FunctionArguments = {baseCS,Year,Month,Day,Hour,Timezone,Latitude,Longitude};
Color = 9;
}
}

transaction graphChange ‘Add bsplineCurve01’
{
feature User.Objects.bsplineCurve01 Bentley.GC.Features.BSplineCurve
{
Color = 3;
MakePeriodic = true;
Points = Transpose(SUN).StartPoint;
}
}

transaction graphChange ‘Add bsplineCurve02’
{
feature User.Objects.bsplineCurve02 Bentley.GC.Features.BSplineCurve
{
Color = 6;
MakePeriodic = false;
Points = SUN.StartPoint;
}
}

About eikeschling

Architect - Computational Design Assistant - Chair of Structural Design Technische Universität München

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: