BBarySlate
Product

Product features · Exact triangle barycentric coordinates

01

In BarySlate, discuss triangle orientation and signed weights before interpreting whether a point lies inside.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Exact triangle barycentric coordinates

● ● ●BarySlate●
A concrete starting point · Exact triangle barycentric coordinates ×
from fractions import Fraction

def barycentric(vertices, point):
    vertices, point = tuple(tuple(v) for v in vertices), tuple(point)
    if len(vertices) != 3 or any(len(v) != 2 for v in vertices) or len(point) != 2:
        raise ValueError("triangle.shape")
    if any(type(c) is not int or abs(c) > 10000 for v in vertices + (point,) for c in v):
        raise ValueError("coordinate.range")
    (x0, y0), (x1, y1), (x2, y2) = vertices
    x, y = point
    den = (y1-y2)*(x0-x2) + (x2-x1)*(y0-y2)
    if den == 0:
        raise ValueError("triangle.degenerate")
    a = Fraction((y1-y2)*(x-x2) + (x2-x1)*(y-y2), den)
    b = Fraction((y2-y0)*(x-x2) + (x0-x2)*(y-y2), den)
    return a, b, 1-a-b
✳Compute exact barycentric weights from three integer vertices and an integer point with coordinate magnitudes at most 10000.
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗