The Triangle object represents a set of three points.

@class
@param [point1={x:0,y:0}] {Point} one of the three points
@param [point2={x:0,y:0}] {Point} one of the three points
@param [point3={x:0,y:0}] {Point} one of the three points
182221
function Triangle ( point1, point2, point3 )
{
    /**
     * @member {Point}
     * @default {x:0,y:0}
     */
    this.p1 = point1 || new Point(0,0);

    /**
     * @member {Point}
     * @default {x:0,y:0}
     */
    this.p2 = point2 || new Point(0,0);

    /**
     * @member {Point}
     * @default {x:0,y:0}
     */
    this.p3 = point3 || new Point(0,0);


    /**
     * @member {Point}
     */
    this.mid0 = new Point ( this.p1.x + ( this.p2.x - this.p1.x )/2,
                            this.p1.y + ( this.p2.y - this.p1.y )/2 );


    /**
     * @member {Point}
     */
    this.mid1 = new Point ( this.p2.x + ( this.p3.x - this.p2.x )/2,
                            this.p2.y + ( this.p3.y - this.p2.y )/2 );
    

    /**
     * @member {Point}
     */
    this.mid2 = new Point ( this.p3.x + ( this.p1.x - this.p3.x )/2,
                            this.p3.y + ( this.p1.y - this.p3.y )/2 );

}
1343269
function() {

            var start = this.start;
            var controlPoint1 = this.controlPoint1;
            var controlPoint2 = this.controlPoint2;
            var end = this.end;

            var x0 = start.x;
            var y0 = start.y;
            var x1 = controlPoint1.x;
            var y1 = controlPoint1.y;
            var x2 = controlPoint2.x;
            var y2 = controlPoint2.y;
            var x3 = end.x;
            var y3 = end.y;

            var points = new Array(); // local extremes
            var tvalues = new Array(); // t values of local extremes
            var bounds = [new Array(), new Array()];

            var a, b, c, t;
            var t1, t2;
            var b2ac, sqrtb2ac;

            for (var i = 0; i < 2; ++i) {

                if (i === 0) {
                    b = 6 * x0 - 12 * x1 + 6 * x2;
                    a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
                    c = 3 * x1 - 3 * x0;

                } else {
                    b = 6 * y0 - 12 * y1 + 6 * y2;
                    a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
                    c = 3 * y1 - 3 * y0;
                }

                if (abs(a) < 1e-12) { // Numerical robustness
                    if (abs(b) < 1e-12) { // Numerical robustness
                        continue;
                    }

                    t = -c / b;
                    if ((0 < t) && (t < 1)) tvalues.push(t);

                    continue;
                }

                b2ac = b * b - 4 * c * a;
                sqrtb2ac = sqrt(b2ac);

                if (b2ac < 0) continue;

                t1 = (-b + sqrtb2ac) / (2 * a);
                if ((0 < t1) && (t1 < 1)) tvalues.push(t1);

                t2 = (-b - sqrtb2ac) / (2 * a);
                if ((0 < t2) && (t2 < 1)) tvalues.push(t2);
            }

            var j = tvalues.length;
            var jlen = j;
            var mt;
            var x, y;

            while (j--) {
                t = tvalues[j];
                mt = 1 - t;

                x = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3);
                bounds[0][j] = x;

                y = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3);
                bounds[1][j] = y;

                points[j] = { X: x, Y: y };
            }

            tvalues[jlen] = 0;
            tvalues[jlen + 1] = 1;

            points[jlen] = { X: x0, Y: y0 };
            points[jlen + 1] = { X: x3, Y: y3 };

            bounds[0][jlen] = x0;
            bounds[1][jlen] = y0;

            bounds[0][jlen + 1] = x3;
            bounds[1][jlen + 1] = y3;

            tvalues.length = jlen + 2;
            bounds[0].length = jlen + 2;
            bounds[1].length = jlen + 2;
            points.length = jlen + 2;

            var left = min.apply(null, bounds[0]);
            var top = min.apply(null, bounds[1]);
            var right = max.apply(null, bounds[0]);
            var bottom = max.apply(null, bounds[1]);

            return new Rect(left, top, (right - left), (bottom - top));
        }
963842
function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2) {
		return (p2.y - p.y) * (p1.x - p.x) > (p1.y - p.y) * (p2.x - p.x);
	}
913113
function tuple3Of(a, b, c) {
    var self = getInstance(this, tuple3Of);
    self.types = rest(arguments);
    return self;
}
1256962
function (/*Point*/ p, /*Point*/ p1, /*Point*/ p2, /*Point*/ p3) {
		return	this._checkCounterclockwise(p, p2, p3) !==
				this._checkCounterclockwise(p1, p2, p3) &&
				this._checkCounterclockwise(p, p1, p2) !==
				this._checkCounterclockwise(p, p1, p3);
	}
274981
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
       return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
              (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
              (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
   }
1177070
def single_triangle():
    
    points = np.zeros((3, 3))
    points[1] = [1, 0, 0]
    points[2] = [0.5, 0.707, 0]
    cells = np.array([[3, 0, 1, 2]], ctypes.c_long)
    return vtki.PolyData(points, cells)
819056
def pointIsInTriangle(p, p1, p2, p3):
    
    p = np.array(p)
    u = np.array(p2) - p1
    v = np.array(p3) - p1
    n = np.cross(u, v)
    w = p - p1
    ln = np.dot(n, n)
    if not ln:
        return True  # degenerate triangle
    gamma = (np.dot(np.cross(u, w), n)) / ln
    beta = (np.dot(np.cross(w, v), n)) / ln
    alpha = 1 - gamma - beta
    if 0 < alpha < 1 and 0 < beta < 1 and 0 < gamma < 1:
        return True
    return False
958972
function (options, base1, base2, base3) {
		var conversion = this.pointAttrToOptions,
			attr,
			option,
			obj = {};

		options = options || {};
		base1 = base1 || {};
		base2 = base2 || {};
		base3 = base3 || {};

		for (attr in conversion) {
			option = conversion[attr];
			obj[attr] = pick(options[option], base1[attr], base2[attr], base3[attr]);
		}
		return obj;
	}
101390
def triangles
      tris = Array.new(tri_indices.size)
      i = 0
      tri_indices.each do |tri_index|
        tris[i] =  self.triangle(i)
        i += 1
      end
      return tris
    end
261028
def _adjacent_tri(self, edge, i):
        
        if not np.isscalar(i):
            i = [x for x in i if x not in edge][0]

        try:
            pt1 = self._edges_lookup[edge]
            pt2 = self._edges_lookup[(edge[1], edge[0])]
        except KeyError:
            return None
            
        if pt1 == i:
            return (edge[1], edge[0], pt2)
        elif pt2 == i:
            return (edge[1], edge[0], pt1)
        else:
            raise RuntimeError("Edge %s and point %d do not form a triangle "
                               "in this mesh." % (edge, i))
268846
public Triangle setPoints(final Point2D a, final Point2D b, final Point2D c)
    {
        return setPoint2DArray(new Point2DArray(a, b, c));
    }
635127
function getter_THREE_Vector4(inst) {
	return [
		inst.x,
		inst.y,
		inst.z,
		inst.w];
}
85421
def slice_triangle_plane(verts, tri, plane_orig, plane_norm):
    
    dists = [point_to_plane_dist(p, plane_orig, plane_norm)
             for p in verts[tri]]

    if np.sign(dists[0]) == np.sign(dists[1]) \
            and np.sign(dists[1]) == np.sign(dists[2]):
        # Triangle is on one side of the plane
        return []

    # Iterate through the edges, cutting the ones that intersect
    intersect_points = []
    for fi in range(3):
        v1 = verts[tri[fi]]
        d1 = dists[fi]
        v2 = verts[tri[(fi + 1) % 3]]
        d2 = dists[(fi + 1) % 3]

        if d1 * d2 < 0:
            # intersection factor (between 0 and 1)
            # here is a nice drawing :
            # https://ravehgonen.files.wordpress.com/2013/02/slide8.png
            s = d1 / (d1 - d2)
            vdir = v2 - v1
            intersect_points.append(v1 + vdir * s)
        elif np.fabs(d1) < 1e-5:
            # point on plane
            intersect_points.append(v1)

    return intersect_points
21977
private static double threePointsAngle(Point vertex, Point A, Point B) {
        double b = pointsDistance(vertex, A);
        double c = pointsDistance(A, B);
        double a = pointsDistance(B, vertex);

        return Math.toDegrees(Math.acos((a * a + b * b - c * c) / (2 * a * b)));

    }
200593
function Point(x, y, z) {
  this.klass = 'Point';
  this.x     = x;
  this.y     = y;
  this.z     = z;
}
55638
public static float triArea2D(float[] verts, int a, int b, int c) {
        float abx = verts[b] - verts[a];
        float abz = verts[b + 2] - verts[a + 2];
        float acx = verts[c] - verts[a];
        float acz = verts[c + 2] - verts[a + 2];
        return acx * abz - abx * acz;
    }