# EasyGeometry::D2::Triangle

## #is\_similar?(other)

{% tabs %}
{% tab title="Description" %}
*Is another `triangle` similar to this one.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:
    other - EasyGeometry::D2::Triangle

Returns:
    boolean (true or false)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 4], [0, 4])
t2 = EasyGeometry::D2::Triangle.new([0, 0], [0, 1], [1, 1])

t1.is_similar?(t2) # true
```

{% endtab %}
{% endtabs %}

## #is\_equilateral?

{% tabs %}
{% tab title="Description" %}
*Are all the `sides` the same length?*

*Precision - 10e-13*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    boolean (true or false)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 4], [0, 4])
t2 = EasyGeometry::D2::Triangle.new([0, 0], [1/2r, Math.sqrt(3)/2], [1, 0])

t1.is_equilateral? # false
t2.is_equilateral? # true
```

{% endtab %}
{% endtabs %}

## #is\_isosceles?

{% tabs %}
{% tab title="Description" %}
*Are two or more of the `sides` the same length?*

*Precision - 10e-13*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    boolean (true or false)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 4], [0, 4])
t2 = EasyGeometry::D2::Triangle.new([0, 0], [1/2r, Math.sqrt(3)/2], [1, 0])

t1.is_isosceles? # true
t2.is_isosceles? # true
```

{% endtab %}
{% endtabs %}

## #is\_scalene?

{% tabs %}
{% tab title="Description" %}
*Are all the `sides` of the triangle of different lengths?*

*Precision - 10e-13*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    boolean (true or false)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 4], [0, 4])
t2 = EasyGeometry::D2::Triangle.new([0, 0], [1/2r, Math.sqrt(3)/2], [1, 0])

t1.is_scalene? # false
t2.is_scalene? # false
```

{% endtab %}
{% endtabs %}

## #is\_right?

{% tabs %}
{% tab title="Description" %}
*Is the `triangle` right-angled.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    boolean (true or false)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 4], [0, 4])
t2 = EasyGeometry::D2::Triangle.new([0, 0], [1/2r, Math.sqrt(3)/2], [1, 0])

t1.is_right? # true
t2.is_right? # false
```

{% endtab %}
{% endtabs %}

## #altitudes

{% tabs %}
{% tab title="Description" %}
*The altitudes of the triangle.*

*An `altitude` of a triangle is a segment through a vertex, perpendicular to the opposite side, with length being the height of the vertex measured from the line containing the side.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Hash(The hash consists of keys which are vertices and values which are Segments.)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [5, 0], [0, 5])

t1.altitudes # {
             #    Point(0, 0): Segment(Point(0, 0), Point(5/2, 5/2)),
             #    Point(5, 0): Segment(Point(5, 0), Point(0, 0)),
             #    Point(0, 5): Segment(Point(0, 5), Point(0, 0)),
             # }
```

{% endtab %}
{% endtabs %}

## #orthocenter

{% tabs %}
{% tab title="Description" %}
*The orthocenter of the `triangle`.*

*The orthocenter is the intersection of the altitudes of a triangle. It may lie `inside`, `outside` or `on the triangle`.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    EasyGeometry::D2::Point
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [5, 0], [0, 5])

t1.orthocenter # Point(0, 0)
```

{% endtab %}
{% endtabs %}

## #circumcenter

{% tabs %}
{% tab title="Description" %}
*The circumcenter of the `triangle`.*

*The circumcenter is the center of the `circumcircle`.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    EasyGeometry::D2::Point
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [1, 0], [0, 1])

t1.circumcenter # Point(0.5, 0.5)
```

{% endtab %}
{% endtabs %}

## #circumradius

{% tabs %}
{% tab title="Description" %}
*The radius of the circumcircle of the `triangle`.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Numeric
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [2, 0], [0, 2])

t1.circumradius # Math.sqrt(2)
```

{% endtab %}
{% endtabs %}

## #bisectors

{% tabs %}
{% tab title="Description" %}
*The angle bisectors of the `triangle`.*

*An angle bisector of a triangle is a straight line through a vertex which cuts the corresponding angle in half.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Hash(each key is a vertex (Point) and each value is the corresponding bisector (Segment).)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [5, 0], [0, 5])

t1.altitudes # {
             #    Point(0, 0): Segment(Point(0, 0), Point(5/2, 5/2)),
             #    Point(5, 0): Segment(Point(5, 0), Point(0, 585786437626905/282842712474619)),
             #    Point(0, 5): Segment(Point(0, 5), Point(585786437626905/282842712474619, 0)),
             # }
```

{% endtab %}
{% endtabs %}

## #incenter

{% tabs %}
{% tab title="Description" %}
*The `center` of the `incircle`.*

*The incircle is the circle which lies inside the triangle and touches all three sides.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    EasyGeometry::D2::Point
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [1, 0], [0, 1])

t1.incenter # Point(1 - Math.sqrt(2)/2, 1 - Math.sqrt(2)/2)
```

{% endtab %}
{% endtabs %}

## #inradius

{% tabs %}
{% tab title="Description" %}
*The radius of the incircle.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Numeric
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [4, 0], [0, 3])

t1.inradius # 1
```

{% endtab %}
{% endtabs %}

## #exradii

{% tabs %}
{% tab title="Description" %}
*The `radius` of excircles of a triangle.*

*An excircle of the triangle is a circle lying outside the triangle, tangent to one of its sides and tangent to the extensions of the other two.*

\[1] <http://mathworld.wolfram.com/Exradius.html>&#x20;

\[2] <http://mathworld.wolfram.com/Excircles.html>
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Hash
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [5, 0], [0, 5])

t1.exradii # {
             #    Segment(Point(0, 0), Point(5, 0)): 3.5355339059327373,
             #    Segment(Point(5, 0), Point(0, 5)): 8.535533905932738,
             #    Segment(Point(0, 5), Point(0, 0)): 3.5355339059327373,
             # }
```

{% endtab %}
{% endtabs %}

## #medians

{% tabs %}
{% tab title="Description" %}
*The medians of the triangle.*

*A median of a triangle is a straight line through a vertex and the midpoint of the opposite side, and divides the triangle into two equal areas.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    Hash(each key is a vertex (Point) and each value is the median (Segment) at that point.)
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [1, 0], [0, 1])

t1.medians # {
             #    Point(0, 0): Segment(Point(0, 0), Point(0.5, 0.5)),
             #    Point(1, 0): Segment(Point(1, 0), Point(0, 0.5)),
             #    Point(0, 1): Segment(Point(0, 1), Point(0.5, 0)),
             # }
```

{% endtab %}
{% endtabs %}

## #medial

{% tabs %}
{% tab title="Description" %}
*The medial triangle of the triangle.*

*The triangle which is formed from the midpoints of the three sides.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    EasyGeometry::D2::Triangle
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [1, 0], [0, 1])

t1.medial # Triangle(Point(0.5, 0), Point(0.5, 0.5), Point(0, 0.5))
```

{% endtab %}
{% endtabs %}

## #eulerline

{% tabs %}
{% tab title="Description" %}
*The Euler line of the triangle.*

*The line which passes through circumcenter, centroid and orthocenter.*
{% endtab %}

{% tab title="Signature" %}

```ruby
Parameters:

Returns:
    EasyGeometry::D2::Line 
    or EasyGeometry::D2::Point for equilateral triangles in which case all centers coincide
    
Errors:
```

{% endtab %}

{% tab title="Example" %}

```ruby
t1 = EasyGeometry::D2::Triangle.new([0, 0], [1, 0], [0, 1])

t1.eulerline # Line(Point(0, 0), Point(0.5, 0.5))
```

{% endtab %}
{% endtabs %}
