Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:54:38+00:00 2026-05-27T23:54:38+00:00

I have a unit right triangle and a value at each of the 3

  • 0

I have a unit right triangle and a value at each of the 3 vertices.
I need to interpolate to find the value at a point inside the triangle.
Hours of searching have turned up nothing that actually tells me how to do this.
Here is my closest attempt, which is actually pretty close but not quite right –

                result = 
                v1 * (1 - x) * (1 - y) +
                v2 * x * (1 - y) +
                v3 * x * y;

v1, v2, and v3 are the values at the 3 vertices of the triangle.
(x, y) is the point in the triangle that you are trying to find the value of.

Any kind of method would help me here. It doesn’t necessarily need to be a unit/right triangle.

Updated info:
I have a grid of evenly spaced points and a value at each point.
I make a triangle out of the nearest 3 points on the grid.
Here is a picture to illustrate it –
enter image description here
So I have to interpolate between 5, 3, and 7 to find the value of x.
The point could also be inside the other triangle, meaning you would interpolate between 5, 7, and the value of the bottom left corner of the square.

In the code I showed, v1 = 5, v2 = 3, v3 = 7.
x is the fractional distance (range [0-1]) in the “x” direction, and y is the fractional distance in the “y” direction.
In the picture’s example, x would probably be about 0.75 and y would be about 0.2

Here are my closest attempts –
enter image description here
Created using –

        if (x > y) //if x > y then the point is in the upper right triangle
            return
                v1 * (1 - x) * (1 - y) +
                v2 * x * (1 - y) +
                v3 * x * y;
        else //bottom left triangle
            return
                v1 * (1 - x) * (1 - y) +
                v4 * (1 - x) * y +
                v3 * x * y;

And another attempt –
enter image description here
Created using –

if (x > y)
            return
                (1 - x) * v1 + (x - y) * v2 + y * v3;
        else
            return
                (1 - y) * v1 + (y - x) * v4 + x * v3;

They’re both close to what I need but obviously not quite right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:54:38+00:00Added an answer on May 27, 2026 at 11:54 pm

    I asked this 3 years ago and have still been working on a way to do this. I do believe it is impossible to do it without artifacts unless using an equilateral triangle.
    Here is a decent way to do it using barycentric coordinates and then adding a technique that gets rid of most of the artifacts.
    v1, v2, v3 are the values at the three points of the triangle. x, y is the point you want to find a value for.

    if (x > y)
            {
                b1 = -(x - 1);
                b2 = (x - 1) - (y - 1);
                b3 = 1 - b1 - b2;
            }
            else
            {
                b1 = -(y - 1);
                b2 = -((x - 1) - (y - 1));
                b3 = 1 - b1 - b2;
            }
    
            float
                abs = x - y;
            if (abs < 0) abs *= -1;
            if (abs < 0.25f)
            {
                abs = 0.25f - abs;
                abs *= abs;
                b1 -= abs;
                b3 -= abs;
            }
    
            b1 *= b1;
            b2 *= b2;
            b3 *= b3;
            float fd = 1 / (b1 + b2 + b3);
            b1 *= fd;
            b2 *= fd;
            b3 *= fd;
    
            return
                    v1 * b1 +
                    v2 * b2 +
                    v3 * b3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Utils unit in my app which, as of right now, only
I have a situation where I need to write some unit tests for some
I have a small unit test macro (defmacro is [expr value] `(if (= ~expr
I have two 32 bit integers HI & LO, and I need to right
Right now my class is set up as: enum Unit{Inches,Centimeters}; Later on I have
I have some unit tests I've written to test my Django application. One test
I have a unit test that fails because headers are already sent. However, the
I have a unit test that I am writing and have run into an
We have some unit tests running against a SQL server 2000 database using the
I have a unit test that creates a mock calls my method to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.