Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

barycentric coordinate calculation correction #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ntoussaint
Copy link

@ntoussaint ntoussaint commented Oct 18, 2023

Barycentric coordinate calculation

I seem to have found a problem in the barycentric coordinate calculation.

The original implementation was giving me incorrect coordinates. This seemed to not influence the "distance", and therefore might have been remained overlooked.

The correction is simple and is not adding computational time.

The calculation originates from this math-stackexchange comment

Let $\overrightarrow{u} = b - a$, $\overrightarrow{v} = c - a$, $\overrightarrow{w} = p - a$ and $\overrightarrow{n} = \overrightarrow{u} \times \overrightarrow{v}$. The barycentric coordinates of $p'$, the projection of $p$ onto the plane $(a,b,c)$ are therefore:

$$ \gamma = [(\overrightarrow{u} \times \overrightarrow{w} ) \cdot \overrightarrow{n} ] / | \overrightarrow{n} |^2 $$

$$ \beta = [(\overrightarrow{w} \times \overrightarrow{v} ) \cdot \overrightarrow{n} ] / | \overrightarrow{n} |^2 $$

$$ \alpha = 1 - \beta - \gamma$$

The coordinates of the projected point is

$$ p' = \alpha a+ \beta b + \gamma c $$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant