# Sagrada Familia Schools Roof

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FvGxNTwCpPvU7w5gCSqF0%2FGaudi_2024-01-26_10-16-56.png?alt=media&#x26;token=6cbc14c9-c7d6-4f6e-9940-e0bb625c5ac5" alt=""><figcaption><p>Sagrida Familia Schools Roof</p></figcaption></figure>

```d
p = Point.ByCoordinates (Math.DegreesToRadians((0..(180*8)..10)),(-10..10..#9)<1>,(Math.Sin((-90..(180*8)..10)+(0..90..10)<1>)*(-1.25..1.25..#10))<1>);
GeometryColor.ByGeometryColor(NurbsSurface.ByPoints(Point.ByCoordinates (p.X,(p.Z<-0.6 ? p.Y+(-p.Y*(p.Z)*0.08) : p.Y),p.Z)).Thicken(0.25).Translate(0,0,1.5),Color.ByARGB(255,255,250,200));
```

While the code required to create this geometry can be packed into a couple of lines of Design, below is a stepwise elaboration of the process.

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FuqIWBJbPxiy4txJula1z%2F01.png?alt=media&#x26;token=babc0fb0-44c4-48f5-8e64-eb242130b8f4" alt=""><figcaption><p>Step 1 : Sine Wave</p></figcaption></figure>

```d
// Sine Wave
r = 0..360;
x = Math.DegreesToRadians(r);
y = 0;
z = Math.Sin(r);
p = Point.ByCoordinates (x,y,z);
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FYUEGPKDGJfcgI4rnh2VV%2F02.png?alt=media&#x26;token=1935fd24-e32d-4504-8c77-6dc142ed87f0" alt=""><figcaption><p>Step 2 : Decrease the point count, increase the wave frequency and amplitude</p></figcaption></figure>

```d
// Decrease point count
r = 0..360..10;

// Increase Frequency
r = (0..360..10) * 4;

// Increase Amplitude
z = Math.Sin(r) * 1.5;
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FVGICrZYXWYvc6gQRWGFU%2F03.png?alt=media&#x26;token=8d7c93fc-414e-463a-a2df-9a5e52c75364" alt=""><figcaption><p>Step 3 : Multiple similar waves along the Y-axis</p></figcaption></figure>

```d
// A range of values along the Y-axis
y = -10..10..#9;

// Repeat waves along the Y-axis
p = Point.ByCoordinates (x,y<1>,z);
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FISMKNDHf2i0wuqtZJRkb%2F04.png?alt=media&#x26;token=d4e09ebc-12fc-4cc5-a821-f0e788e490ae" alt=""><figcaption><p>Step 4 : Nurbs Surface</p></figcaption></figure>

```d
// Nurbs Surface
s = NurbsSurface.ByPoints(p);
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2Ft9eO4gG1Khpfa2lccb4K%2F05.png?alt=media&#x26;token=b3b14f83-8b9e-405d-a12c-7b364db67503" alt=""><figcaption><p>Step 5 : Crest (from trough) at start of last wave</p></figcaption></figure>

```d
// Increase Z incrementally
z = Math.Sin(r +(0..90..#9)<1>) * 1.5;

// Apply to wave profiles
p = Point.ByCoordinates (x,y<1>,z<1>);
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FH966xHMjx1Ux13271hvX%2F06.png?alt=media&#x26;token=794c9acf-8ad0-49eb-9501-12799f9bfec5" alt=""><figcaption><p>Step 6 : Flattening amplitude towards the middle</p></figcaption></figure>

```d
// Incrementally minimizing amplitude of waves towards the middle
a = List.Flatten([1.5..0..#4,0,0..1.5..#4],-1);
z = Math.Sin(r +(0..90..#9)<1>) * a;
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FdTNj4oza6gj9Csdw5f5u%2F07.png?alt=media&#x26;token=58ddc918-f370-4b6f-a91d-2d8cf384709a" alt=""><figcaption><p>Step 7 : Trough Protrusion</p></figcaption></figure>

```d
// Trough Protrusion
tp = p.Z < -1.4 ? p.Y+(-p.Y*(p.Z)*0.1) : p.Y;
pp = Point.ByCoordinates(p.X,tp,p.Z);
```

<figure><img src="https://1430428134-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Ld8QK19sjP1I9rhLouo%2Fuploads%2FFp8fKDuNt8heI8yU4Y99%2F08.png?alt=media&#x26;token=5de3630e-fb39-40cd-8aef-cd596d67f146" alt=""><figcaption><p>Step 8 : Thicken</p></figcaption></figure>

```d
// Sine Wave
r = (0..360..10) * 4;
x = Math.DegreesToRadians(r);
y = -10..10..#9;
a = List.Flatten([1.5..0..#4,0,0..1.5..#4],-1);
z = Math.Sin(r +(0..90..#9)<1>) * a;
p = Point.ByCoordinates (x,y<1>,z<1>);

// Trough Protrusion
tp = p.Z<-1.4 ? p.Y+(-p.Y*(p.Z)*0.1) : p.Y;
pp = Point.ByCoordinates(p.X,tp,p.Z);

// Nurbs Surface
s = NurbsSurface.ByPoints(pp).Thicken(0.25);
```
