All ▲lgorithms

All ▲lgorithms

  • Algorithms
  • Categories
  • Libraries
  • Blog

›Computational geometry

Artificial Intelligence

  • Dbscan
  • Isodata
  • Linear regression
  • Logistic regression
  • Neutral style transfer
  • Sat
  • Tsp
  • A star
  • Artificial neutral network
  • Convolutional neutral network
  • Decision tree
  • Factorization machines
  • Gaussian mixtrue model
  • Gradient boostring trees
  • Hierachical clustering
  • Image processing
  • K nearest neighbors
  • K means
  • Minimax
  • Native bayes
  • Nearest sequence memory
  • Neutral network
  • Perceptron
  • Principal component analysis
  • Q learning
  • Random forest
  • Restricted boltzman machine

Backtracking

  • Algorithm x
  • Crossword Puzzle
  • Knight tour
  • M coloring problem
  • N queen
  • Number of ways in maze
  • Partitions of set
  • Permutation of strings
  • Powerset
  • Rat in maze
  • Subset sum
  • Sudoku solve

Bit manipulation

  • Adding using bits
  • Bit divisor
  • Byte swapper
  • Convert numbers to binary
  • Count set bits
  • Flip bits
  • Hamming distace
  • Invert bit
  • Lonely integer
  • Magic number
  • Maximun xor value
  • Power of 2
  • Subset generation
  • Sum binary numbers
  • Sum equals xor
  • Thrice unique number
  • Twice unique number
  • Xor swap

Cellular automaton

  • Brians brain
  • Conways game of life
  • Elementary cellular automata
  • Generic algorithm
  • Langtons ant
  • Nobili cellular automata
  • Von neoumann cellular automata

Computational geometry

  • 2d line intersection
  • 2d separating axis test
  • Area of polygon
  • Area of triangle
  • Axis aligned bounding box collision
  • Bresenham line
  • Chans algorithm
  • Cohen sutherland lineclip
  • Distance between points
  • Graham scan
  • Halfplane intersection
  • Jarvis march
  • Quickull
  • Sphere tetrahedron intersection
  • Sutherland hodgeman clipping

Cryptography

  • Affine cipher
  • Atbash cipher
  • Autokey cipher
  • Baconian cipher
  • Caesar cipher
  • Colummnar cipher
  • Vigenere cipher

Data structures

  • Bag
  • Hashes
  • Linked list
  • List
  • Queue
  • Stack
  • Tree

Divide and conquer

  • Strassen matrix manipulation
  • Closest pair of point
  • Inversion count
  • Karatsuba multiplication
  • Maximum contiguous subsequence sum
  • Merge sort using divide and conquer
  • Quick sort using divide and conquer
  • Tournament method to find min max
  • Warnock algorithm
  • X power y

Dynamic programming

  • Array median
  • Optima binary search tree

Gaming theory

  • Nim next best move game
  • Nim win loss game
  • Grundy numbers kayle game

Graphs

  • Bipartite check
  • Adjacency lists graphs representation

Greedy algorithms

  • Activity selection
  • Dijkstra shortest path
  • Egyptian fraction

Math

  • 2 sum
  • Add polynomials
  • Amicable numbers
  • Armstrong numbers
  • Automorphic numbers
  • Average stream numbers
  • Babylonian method
  • Binomial coefficient
  • Catalan number
  • Check is square
  • Convolution
  • Coprime numbers
  • Count digits
  • Count trailing zeroes
  • Decoding of string
  • Delannoy number
  • Derangements
  • Dfa division
  • Diophantine
  • Divided differences
  • Euler totient
  • Exponentiation power
  • Factorial
  • Fast fourier transform
  • Fast inverse square root

Networking

  • Packet sniffer
  • Determine endianess
  • Validate ip

Numerical analysis

  • Integral
  • Monte carlo
  • Runge kutt

Randomized algorithms

  • Birthday paradox
  • Karger minimum cut algorithm
  • Kth smallest element algorithm
  • Random from stream
  • Random node linked list
  • Randomized quicksort
  • Reservoir sampling
  • Shuffle an array

Searches

  • Binary search
  • Exponential search
  • Fibonacci search
  • Fuzzy search
  • Interpolation search
  • Jump search
  • Linear search
  • Ternay search

Selections algorithms

  • Median of medians
  • Quick select

Sorting

  • Bead sort
  • Bogo sort
  • Bubble sort
  • Bucket sort
  • Circle sort
  • Comb sort
  • Counting sort
  • Cycle sort
  • Flash sort
  • Gnome sort
  • Heap sort
  • Insertion sort
  • Intro sort
  • Merge sort
  • Pipeonhole sort
  • Quick sort
  • Radix sort
  • Selection sort
  • Shaker sort
  • Shell sort
  • Sleep sort
  • Stooge sort
  • Topological sort
  • Tree sort

Strings

  • Aho corasick algorithm
  • Anagram search
  • Arithmetic on large numbers
  • Boyer moore algorithm
  • Finite automata
  • Kasai algorithm
  • Kmp algorithm
  • Levenshteing distance
  • Lipogram checker

Online challenges

  • Coderbyte
  • Code chef
  • Code eval
  • Hackerearth
  • Hackerrank
  • Leetcode
  • Project euler
  • Rosalind
  • Spoj
  • Top coder

No category

  • Average
  • Biggest of n numbers
  • Biggest suffix
  • Fifteen puzzle
  • Jaccard similarity
  • Jose phus problem
  • Lapindrom checker
  • Leap year
  • Magic square
  • Majority element
  • Minimum subarray size with degree
  • No operator addition
  • Paint fill
  • Split list
  • Tokenizer
  • Unique number

Area of triangle

A triangle is a polygon with three sides and three vertices. Calculating its area efficiently depends on what is known about it.

From base and height

The basic formula assumes knowledge of the length of one of the sides (called base) and the length of the height of the triangle with respect to that side. This height is the segment that originates from the vertex that is not on the side we know about, and intersects the side we know about at a right angle.

Assuming the base is put horizontally and the third vertex above it, the following picture results. Quantity b is the length of the bottom side, and h the height with respect to it.

Triangle

Height can sometimes be referred to as altitude.

Formula

In this case, the area is calculated as follows:

T=\frac{b \cdot h}{2}

Algorithm

The algorithm can be derived directly from the defining formula above:

triangle_area_basic (b, h) {
   return b * h / 2;
}

In the euclidean plane

In this section, it is assumed that the triangle is known by the coordinates of its three vertices A, B, and C on the plane:

A, B, and C in the plane

Formula

In this case, the area of the triangle can be calculated as follows:

T = \frac{|(x_B - x_A)(y_C - y_A) - (x_C - x_A)(y_B - y_A)|}{2}

Algorithm

The following algorithm is a direct translation of the formula:

triangle_area_plane (x_A, y_A, x_B, y_B, x_C, y_C) {
    return abs((x_B - x_A) * (y_C - y_A) - (x_C - x_A) * (y_B - y_A)) / 2;
}

In the euclidean space

In this section, it is assumed that the triangle is known by the coordinates of its three vertices A, B, and C in the three-dimensional space:

Formula

The formula to calculate the area involves calculating the determinant of three matrices:

triangle area in the plane

The absolute value of each determinant is the double of the area of the triangle obtained by projecting the target triangle onto one of the coordinate planes, which allows reusing the formula for the triangle in the plane in a previous section.

Algorithm

The following algorithm leverages the triangle area calculation in the plane, described in a previous section and not repeated here:

/* Assume that A, B, and C are 3-dimensional arrays
   X at index 0, Y at index 1, Z at index 2         */
triangle_area_space (A, B, C) {
    x = triangle_area_plane(A[1], A[2], B[1], B[2], C[1], C[2]);
    y = triangle_area_plane(A[2], A[0], B[2], B[0], C[2], C[0]);
    z = triangle_area_plane(A[0], A[1], B[0], B[1], C[0], C[1]);
    return sqrt(x * x + y * y + z * z);
}

Note: the division by two in the formula is already included in the result from the calculation of the area in the plane.

Performance

All algorithms for calculating the area of a triangle in the sections above execute in constant time (O(0)).

Implementations

LanguageLink

Helpful Links

  • Triangle
  • Area of Triangles and Polygons
Last updated on 2020-10-3 by Flavio Poletti
← Area of polygonAxis aligned bounding box collision →
  • From base and height
    • Formula
    • Algorithm
  • In the euclidean plane
    • Formula
    • Algorithm
  • In the euclidean space
    • Formula
    • Algorithm
  • Performance
  • Implementations
  • Helpful Links
All ▲lgorithms
Implementations
C++JavaJavascriptRubyGoMore ...
Libraries Docs
PythonJavaJavascriptMore ...
Community
GithubGitterTwitterInstagramFacebook
More
BlogStickers & T-ShirtsContributingCategories
Powered by Tryhtml
Copyright © 2021 The All ▲lgorithms Project.