geom_util.cpp

来自「The goal of this project is to explore t」· C++ 代码 · 共 43 行

CPP
43
字号
/*+-------------------------------------------------------------------
  Ben Landon
  CSCI E-235

  geom_util.cpp 

*/

#include <assert.h>
#include "geom_util.hpp"

void get_barycentric_parameters_2D (float x,  float y,
				    float x0, float y0, 
				    float x1, float y1, 
				    float x2, float y2,
				    float& t1, float& t2)
{
    float v11 = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0);
    float v22 = (x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0);

    float v12 = (x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0);
    float v21=  v12;

    float vx1 = (x - x0) * (x1 - x0) + (y - y0) * (y1 - y0);
    float vx2 = (x - x0) * (x2 - x0) + (y - y0) * (y2 - y0);

    float denom = v11 * v22 - v21 * v12;
    
    float t1_num = vx1 * v22 - vx2 * v12;
    float t2_num = v11 * vx2 - v12 * vx1;

    if (denom == 0)
    {
	assert(false);
	return; // not sure what to do here
    }

    t1 = t1_num / denom;
    t2 = t2_num / denom;
    
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?