<commit_before># Vectors

## Exercise

In this lesson, you will write a GLSL function which computes the unit angle bisector between two vectors.  That is, it is the vector whose length is `1` and whose angle is halfway between two vectors.  If the vectors are parallel or zero, you can return whatever you want. A file called <a href="/open/03-intro-3">`vectors.glsl` has been created for you as a template</a>.

As an example, if `a = vec2(1,0)` and `b = vec2(0,1)`, then you should return the result `vec2(sqrt(2)/2, sqrt(2)/2)`.

**Hint** It is useful to remember the angle bisector theorem.  In ascii art, suppose we have two vectors, A and B.  Then the angle bisector between A and B is the vector C:

```
 B
 ^
 |\
 | \^ C
 | /\
 |/  \
 *----> A
 O
```

In this situation, the angle bisector theorem tells us the following information about the ratio of the lengths of these vectors:

```glsl
length(B - C) / length(C - A) == length(B) / length(A)
```

Using the above equation, solve for the position of C and then normalize it to unit length.

***

After scalars, the next most important data type in GLSL are vectors.  GLSL comes with built in types for small vectors with up to 4 components.  Like scalars, vectors come in boolean, integer and floating point varieties which are declared using the following syntax:

* `bvec2, bvec3, bvec4`: Boolean vector
* `ivec2, ivec3, ivec4`: Integer vector
* `vec2, vec3, vec4`: Floating point vector

Floating point vectors and can have the same precision specifiers as floats, so `lowp vec2` is a low precision float vector, for example.  The vector type keywords are also used to construct vectors.  Here are some examples:
<commit_msg>fix typo in 03-intro-3<commit_after># Vectors

## Exercise

In this lesson, you will write a GLSL function which computes the unit angle bisector between two vectors.  That is, it is the vector whose length is `1` and whose angle is halfway between two vectors.  If the vectors are parallel or zero, you can return whatever you want. A file called <a href="/open/03-intro-3">`vectors.glsl` has been created for you as a template</a>.

As an example, if `a = vec2(1,0)` and `b = vec2(0,1)`, then you should return the result `vec2(sqrt(2)/2, sqrt(2)/2)`.

**Hint** It is useful to remember the angle bisector theorem.  In ascii art, suppose we have two vectors, A and B.  Then the angle bisector between A and B is the vector C:

```
 B
 ^
 |\
 | \^ C
 | /\
 |/  \
 *----> A
 O
```

In this situation, the angle bisector theorem tells us the following information about the ratio of the lengths of these vectors:

```glsl
length(B - C) / length(C - A) == length(B) / length(A)
```

Using the above equation, solve for the position of C and then normalize it to unit length.

***

After scalars, the next most important data type in GLSL are vectors.  GLSL comes with built in types for small vectors with up to 4 components.  Like scalars, vectors come in boolean, integer and floating point varieties which are declared using the following syntax:

* `bvec2, bvec3, bvec4`: Boolean vector
* `ivec2, ivec3, ivec4`: Integer vector
* `vec2, vec3, vec4`: Floating point vector

Floating point vectors can have the same precision specifiers as floats, so `lowp vec2` is a low precision float vector, for example.  The vector type keywords are also used to construct vectors.  Here are some examples:

{'fraction_non_alphanumeric': 0.08744460856720827, 'fraction_numerical': 0.01624815361890694, 'mean_word_length': 3.8302425106990015, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6790275', 'n_tokens_mistral': 1023, 'n_tokens_neox': 981, 'n_words': 524}