# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>

float edgeFunction(const glm::vec3& v0, const glm::vec3& v1, const glm::vec2& p)
{
return (p.x - v0.x) * (v1.y - v0.x) - (p.y - v0.y) * (v1.x - v0.x);
}

glm::vec2 screen2NDC(const glm::vec2& screen)
{
glm::vec2 result;
result.x = (screen.x + 1) / 2;
result.y = (1 - screen.y) / 2;
return result;
}

glm::vec3 NDC2raster(const glm::vec2& NDC, int width, int height)
{
glm::vec3 result;
result.x = (int)(NDC.x * width);
result.y = (int)(NDC.y * height);
result.z = 1; // no cam point

if (result.x == width)
result.x = width - 1;
if (result.y == height)
result.y = height - 1;
return result;
}

int main()
{
int width = 100, height = 100;
float l = -1, r = 1, b = 1, t = -1;

//screen space
glm::vec2 screen_p[3] = { glm::vec2(-0.3, -0.6), glm::vec2(0, 0.7), glm::vec2(0.3, -0.6) };

//screen to NDC
glm::vec2 NDC_p[3];
for (int i = 0; i < 3; i++)
NDC_p[i] = screen2NDC(screen_p[i]);

//NDC to raster
glm::vec3 raster_p[3];
for (int i = 0; i < 3; i++)
raster_p[i] = NDC2raster(NDC_p[i], width, height);

//testing point on raster space
glm::vec2 p1(50, 50), p2(90, 50);

//test1
bool inside = true;
for (int i = 0; i < 3; i++)
{
if (edgeFunction(raster_p[i % 3], raster_p[(i + 2) % 3], p1) < 0) {
inside = false;
break;
}
}
std::cout << "P(50,50) : " << (inside ? "true" : "false") << std::endl;
//test2
inside = true;
for (int i = 0; i < 3; i++)
{
if (edgeFunction(raster_p[i % 3], raster_p[(i + 2) % 3], p2) < 0) {
inside = false;
break;
}
}
std::cout << "P(90,50) : " << (inside ? "true" : "false") << std::endl;

return 0;
}

# data[].attributes.body
#include<iostream>
#include<glm/glm.hpp> // glm 모든기능 포함
//#include<glm/vec2.hpp> 일부기능만 가져오기
#include <glm/gtx/string_cast.hpp> // 출력하기위해
//using namespace glm;
#include<glm/gtx/transform.hpp>

#include <glm/gtx/matrix_transform_2d.hpp>

#define GLM_FORCE_SWIZZLE

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

#include <glm/mat4x4.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x));
}

int main() {

glm::vec2 v2 = { 0.3,-0.6 };
glm::vec2 v1 = {0,0.7 };
glm::vec2 v0 = { -0.3,-0.6 };
glm::vec2 point1 = { 50,50 };
glm::vec2 point2 = { 90,50 };

//screen --> ndc
glm::vec2 p0,p1,p2;
p0.x = (v0.x + 1) / 2;
p0.y = (1 - v0.y) / 2;
p1.x = (v1.x + 1) / 2;
p1.y = (1 - v1.y) / 2;
p2.x = (v2.x + 1) / 2;
p2.y = (1 - v2.y) / 2;

glm::ivec2 p0raster,p1raster,p2raster;

//ndc --> raster
p0raster.x = (int)(p0.x * 100);
p0raster.y = (int)(p0.y * 100);
p1raster.x = (int)(p1.x * 100);
p1raster.y = (int)(p1.y * 100);
p2raster.x = (int)(p2.x * 100);
p2raster.y = (int)(p2.y * 100);

if (p0raster.x == 100) p0raster.x = 100 - 1;
if (p0raster.y == 100) p0raster.y = 100 - 1;
if (p1raster.x == 100) p1raster.x = 100 - 1;
if (p1raster.y == 100) p1raster.y = 100 - 1;
if (p2raster.x == 100) p2raster.x = 100 - 1;
if (p2raster.y == 100) p2raster.y = 100 - 1;

float pw0 = edgeFunction(p0raster, p2raster, point1);
float pw1 = edgeFunction(p2raster, p1raster, point1);
float pw2 = edgeFunction(p1raster, p0raster, point1);

std::cout << "p1에 대한 edgefunction 값" << std::endl;
std::cout << pw0 << std::endl;
std::cout << pw1 << std::endl;
std::cout << pw2 << std::endl;

bool inside;
if (pw0 > 0 && pw1 > 0 && pw2 > 0) inside = true;
else inside = false;
std::cout << "{50,50}이 안에 있는가" << (inside == 1 ? "true" : "false") << std::endl;

float w0 = edgeFunction(p0raster, p2raster, point2);
float w1 = edgeFunction(p2raster, p1raster, point2);
float w2 = edgeFunction(p1raster, p0raster, point2);

std::cout << "p2에 대한 edgefunction 값" << std::endl;
std::cout << w0 << std::endl;
std::cout << w1 << std::endl;
std::cout << w2 << std::endl;

if (w0 > 0 && w1 > 0 && w2 > 0) inside = true;
else inside = false;
std::cout << "{90,50}이 안에 있는가" << (inside==1?"true" : "false") << std::endl;

return 0;
}

# data[].attributes.body
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp >
#include <iostream>

#define IMG_WIDTH 100
#define IMG_HEIGHT 100

float edgeFunction(const glm::vec3& a,const glm::vec3& b, const glm::vec3& c)
{
return (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}
glm::vec3 ScreenToNDC(glm::vec3 a)
{
return glm::vec3((a.x + 1.f) * 0.5f, (1.f - a.y) * 0.5f, 1);
}

glm::vec3 NDC_To_Raster(glm::vec3 a, int width, int height)
{
glm::vec3 Raster_a(glm::vec3((int)(a.x * width), (int)(a.y * height), 1));
if (Raster_a.x == width)
Raster_a.x = width - 1;
if (Raster_a.y == height)
Raster_a.y = height - 1;
return Raster_a;
}
glm::vec3 ScreenToRaster(glm::vec3 a, int width, int height)
{
glm::vec3 ndc_a = ScreenToNDC(a);
return NDC_To_Raster(ndc_a, width, height);
}
bool IsInside(glm::vec3 v0, glm::vec3 v1, glm::vec3 v2, glm::vec3 p)
{
float w0 = edgeFunction(v1, v2, p);
float w1 = edgeFunction(v2, v0, p);
float w2 = edgeFunction(v0, v1, p);

bool inside = true;

glm::vec3 edge0 = v2 - v1;
glm::vec3 edge1 = v0 - v2;
glm::vec3 edge2 = v1 - v0;

bool overlaps = true;

return overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
}
int main()
{
glm::vec3 v0(-0.3, -0.6, 1);
glm::vec3 v2(0, 0.7, 1);
glm::vec3 v1(0.3, -0.6, 1);
glm::vec3 p1(50, 50, 1);
glm::vec3 p2(90, 50, 1);

glm::vec3 v_0 = ScreenToRaster(v0, IMG_WIDTH, IMG_HEIGHT);
glm::vec3 v_1 = ScreenToRaster(v1, IMG_WIDTH, IMG_HEIGHT);
glm::vec3 v_2 = ScreenToRaster(v2, IMG_WIDTH, IMG_HEIGHT);

std::cout << "v'0 : " << glm::to_string(v_0) << std::endl;
std::cout << "v'1 : " << glm::to_string(v_1) << std::endl;
std::cout << "v'2 : " << glm::to_string(v_2) << std::endl;

std::cout << "p1 is inside? : " << IsInside(v_0, v_1, v_2, p1) << std::endl;
std::cout << "p2 is inside? : " << IsInside(v_0, v_1, v_2, p2) << std::endl;
return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

bool edgeFunction(const glm::vec2 &a, const glm::vec2 &b, const glm::vec2 &c) {
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
int width = 100;
int height = 100;

glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0, 0.7);
glm::vec2 v2(0.3, -0.6);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v0Ndc;
glm::vec2 v1Ndc;
glm::vec2 v2Ndc;

v0Ndc.x = (v0.x + 1) / 2;
v0Ndc.y = (1 - v0.y) / 2;
v1Ndc.x = (v1.x + 1) / 2;
v1Ndc.y = (1 - v1.y) / 2;
v2Ndc.x = (v2.x + 1) / 2;
v2Ndc.y = (1 - v2.y) / 2;

glm::vec2 v0Ras;
glm::vec2 v1Ras;
glm::vec2 v2Ras;

v0Ras.x = (int)(v0Ndc.x * width);
v0Ras.y = (int)(v0Ndc.x * height);
v1Ras.x = (int)(v1Ndc.x * width);
v1Ras.y = (int)(v1Ndc.x * height);
v2Ras.x = (int)(v2Ndc.x * width);
v2Ras.y = (int)(v2Ndc.x * height);

if (v0Ras.x == width) v0Ras.x = width - 1;
if (v0Ras.y == height) v0Ras.y = width - 1;
if (v1Ras.x == width) v1Ras.x = width - 1;
if (v1Ras.y == height) v1Ras.y = width - 1;
if (v2Ras.x == width) v2Ras.x = width - 1;
if (v2Ras.y == height) v2Ras.y = width - 1;

bool w0 = edgeFunction(v1Ras, v2Ras, p1);
bool w1 = edgeFunction(v2Ras, v0Ras, p1);
bool w2 = edgeFunction(v0Ras, v1Ras, p1);
bool _w0 = edgeFunction(v1Ras, v2Ras, p2);
bool _w1 = edgeFunction(v2Ras, v0Ras, p2);
bool _w2 = edgeFunction(v0Ras, v1Ras, p2);

glm::vec2 edge0 = v2Ras - v1Ras;
glm::vec2 edge1 = v0Ras - v2Ras;
glm::vec2 edge2 = v1Ras - v0Ras;

bool isP1 = true;
bool isP2 = true;

if (w0 == true && w1 == true && w2 == true)
isP1 = true;
else
isP1 = false;

if (_w0 == true && _w1 == true && _w2 == true)
isP2 = true;
else
isP2 = false;

if (isP1)
std::cout << "p1 is inside" << std::endl;
else if(!isP1)
std::cout << "p1 is outside" << std::endl;

if (isP2)
std::cout << "p2 is inside" << std::endl;
else if (!isP2)
std::cout << "p2 is outside" << std::endl;

}

# data[].attributes.body
#include<iostream>
#include<glm/glm.hpp>
#include<glm/gtx/string_cast.hpp>
#include<glm/matrix.hpp>
#include<glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
float edgeFunction(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c);
int main() {
glm::vec3 v0(-0.3,-0.6,0);
glm::vec3 v1(0,0.7,0);
glm::vec3 v2(0.3,-0.6,0);
glm::vec3 p1(50,50,0);
glm::vec3 p2(90,50,0);

v0.x = ((v0.x + 1) / 2) * 100;
v0.y = ((1 - v0.y)/2)*100;
v1.x = ((v1.x + 1) / 2) * 100;
v1.y = ((1 - v1.y) / 2) * 100;
v2.x = ((v2.x + 1) / 2) * 100;
v2.y = ((1 - v2.y) / 2) * 100;

float w0 = edgeFunction(v0, v1, p1);
float w1 = edgeFunction(v1, v2, p1);
float w2 = edgeFunction(v2, v0, p1);
std::cout << w0 << std::endl;
std::cout << w1 << std::endl;
std::cout << w2 << std::endl;

if (w0 > 0 && w1 > 0 && w2 > 0) {
std::cout <<"p1은 삼각형 내부에 존재함." << std::endl;
}
else {
std::cout << "p1은 삼각형 외부에 존재함." << std::endl;
}

float z0 = edgeFunction(v0, v1, p2);
float z1 = edgeFunction(v1, v2, p2);
float z2 = edgeFunction(v2, v0, p2);

std::cout << z0 << std::endl;
std::cout << z1 << std::endl;
std::cout << z2 << std::endl;

if (z0 > 0 && z1 > 0 && z2 > 0) {
std::cout << "p2은 삼각형 내부에 존재함." << std::endl;
}
else {
std::cout << "p2은 삼각형 외부에 존재함." << std::endl;
}

}

float edgeFunction(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c)
{

return(c[0] - a[0])* (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);

}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtc/constants.hpp>
#define GLM_FORCE_SWIZZLE
const double DEGREES_TO_RADIAS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();
#define Wighth 100
#define Herght 100

using namespace glm;
using namespace std;

vec2 normallized_(vec2& x)
{
x.x = (x.x + 1) / 2;
x.y = (x.y + 1) / 2;
return x;
}

vec2 rester_space(vec2& x)
{
x.x = x.x * Wighth;
x.y = -1 * x.y * Herght;
return x;
}

bool edgeFunction(vec2 a, vec2 b, vec2 c)
{
if(a.y >= 0)
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
else
return (-(c.x - a.x) * (b.y - a.y) + (-c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
vec2 p1 = { 50,50 };
vec2 p2 = { 90,50 };

vec2 v0 = { -0.3f, -0.6f };
vec2 v1 = { 0, 0.7f };
vec2 v2 = { 0.3f, -0.6f };

v0 = normallized_(v0);
v1 = normallized_(v1);
v2 = normallized_(v2);

v0 = rester_space(v0);
v1 = rester_space(v1);
v2 = rester_space(v2);

cout << "v0[" << v0.x << ", " << v0.y << "], v1[" << v1.x << ", " << v1.y << "], v2[" << v2.x << ", " << v2.y << "]" "\n ";

float w0 = edgeFunction(v1, v2, p1);
float w1 = edgeFunction(v2, v0, p1);
float w2 = edgeFunction(v0, v1, p1);

float w0_ = edgeFunction(v1, v2, p2);
float w1_ = edgeFunction(v2, v0, p2);
float w2_ = edgeFunction(v0, v1, p2);

vec2 edge0 = v2 - v1;
vec2 edge1 = v0 - v2;
vec2 edge2 = v1 - v0;

bool overlaps = true;
bool overlaps_ = true;

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트,

cout << "" << w0 << ", " << w1 << ", " << w2 << "\n ";
cout << "" << w0_ << ", " << w1_ << ", " << w2_ << "\n ";

overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1 > 0));
overlaps &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2 > 0));

overlaps_ &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0_ > 0));
overlaps_ &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1_ > 0));
overlaps_ &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2_ > 0));

cout << "점 P1의 위치: [ " << overlaps << " ]\n";
cout << "점 P2의 위치: [ " << overlaps_ << " ]\n\n(1이면 true, 0이면 false)\n";

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp >
float edgeFunction(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c)
{
return ((c.x - a.x) * (b.y- a.y) - (c.y - a.y) * (b.x - a.x));
}
bool InsideCheck(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c, const glm::vec3& p)
{
float overlaps[3]; // must be same direction
overlaps[0] = edgeFunction(a,c, p);
overlaps[1] = edgeFunction(c,b,p);
overlaps[2] = edgeFunction(b,a,p);

std::cout << overlaps[0] << std::endl;
std::cout << overlaps[1] << std::endl;
std::cout << overlaps[2] << std::endl;

bool isIn=true;
for (int i = 0; i < 3; )
{
if (overlaps[i] >= 0 && isIn)
{
isIn = true;
i++;
}
else
return false;
}

return isIn;
}

int main()
{

glm::vec2 imageSize = { 100,100 };
//screen

glm::vec2 v[3];
v[0] = {-0.3, -0.6};
v[1] = { 0, 0.7 };
v[2] = { 0.3, -0.6};

glm::vec2 pNDCv[3];
for (int i = 0; i < 3; i++)
{
pNDCv[i].x = ( v[i].x + 1 ) / 2;
pNDCv[i].y = (1 - v[i].y) / 2;
}

//Raster // must be int
glm::vec3 pRaster[3];
for (int i = 0; i < 3; i++)
{
pRaster[i].x =(int)(pNDCv[i].x* imageSize.x);
pRaster[i].y =  (int)(pNDCv[i].y * imageSize.y); // height. make upsidedown
pRaster[i].z = 1;

if (pRaster[i].x == imageSize.x)
pRaster[i].x -= 1;

if (pRaster[i].y == imageSize.y)
pRaster[i].y -= 1;
}

//insideout check

glm::vec3 p1 = { 50,50,1 };
glm::vec3 p2 = { 90,50,1 };

for (int i = 0; i < 3; i++)
{
std::cout << "in Sreen v" << i << " : " << glm::to_string(v[i]) << std::endl;
}
for (int i = 0; i < 3; i++)
{
std::cout << "in NDC v" << i << " : " << glm::to_string(pNDCv[i]) << std::endl;
}
for (int i = 0; i < 3; i++)
{
std::cout << "in raster v" << i << " : " << glm::to_string(pRaster[i]) << std::endl;
}
std::cout << "p1 is inside? : " << InsideCheck(pRaster[0], pRaster[1], pRaster[2],p1) << std::endl;
std::cout << "p2 is inside? : " << InsideCheck(pRaster[0], pRaster[1], pRaster[2], p2) << std::endl;

return 0;
}

//NDC
//glm::vec2 pNDCv[3];
//float l = -0.3;
//float r = 0.3;
//float t = 0.7;
//float b = -0.6;

//pNDCv[i].x = 2 * v[i].x / (r - l) - (r + l) / (r - l);
//pNDCv[i].y = 2 * v[i].x / (t - b) - (t + b) / (t - b);
//
//float overlaps2[3]; // counterClockwise
//overlaps2[0] = edgeFunction(pRaster[0], pRaster[2], p2);
//overlaps2[1] = edgeFunction(pRaster[2], pRaster[1], p2);
//overlaps2[2] = edgeFunction(pRaster[1], pRaster[0], p2);

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>

using namespace std;

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return { (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]) };
}
int main() {
int width = 100;
int height = 100;

glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0, 0.7);
glm::vec2 v2(0.3, -0.6);

glm::vec2 v0NDC = { (v0.x + 1) / 2, (1 - v0.y) / 2 };
glm::vec2 v1NDC = { (v1.x + 1) / 2, (1 - v1.y) / 2 };
glm::vec2 v2NDC = { (v2.x + 1) / 2, (1 - v2.y) / 2 };

glm::ivec2 v0Raster = { (int)((v0NDC.x) * width), (int)((v0NDC.y) * height) };
glm::ivec2 v1Raster = { (int)((v1NDC.x) * width), (int)((v1NDC.y) * height) };
glm::ivec2 v2Raster = { (int)((v2NDC.x) * width), (int)((v2NDC.y) * height) };

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

cout << "P1(50, 50)에 대해 inside/outside 테스트" << endl;
cout << "edge(v0, v1, p1): " << edgeFunction(v1Raster, v0Raster, p1) << endl;
cout << "edge(v1, v2, p1): " << edgeFunction(v2Raster, v1Raster, p1) << endl;
cout << "edge(v2, v0, p1): " << edgeFunction(v0Raster, v2Raster, p1) << endl;
if (edgeFunction(v1Raster, v0Raster, p1) >= 0 && edgeFunction(v2Raster, v1Raster, p1) >= 0 && edgeFunction(v0Raster, v2Raster, p1) >= 0) {
cout << "inside"<<endl;
}
else
{
cout << "outside" << endl;
}
cout << "P2(90, 50)에 대해 inside/outside 테스트" << endl;
cout << "edge(v0, v1, p2): " << edgeFunction(v1Raster, v0Raster, p2) << endl;
cout << "edge(v1, v2, p2): " << edgeFunction(v2Raster, v1Raster, p2) << endl;
cout << "edge(v2, v0, p2): " << edgeFunction(v0Raster, v2Raster, p2) << endl;
if (edgeFunction(v1Raster, v0Raster, p2) >= 0 && edgeFunction(v2Raster, v1Raster, p2) >= 0 && edgeFunction(v0Raster, v2Raster, p2) >= 0) {
cout << "inside" << endl;
}
else
{
cout << "outside" << endl;
}
return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

#define GLM_FORCE_SWIZZLE // Swizzle operator ex) B.yx = A.wy; B = A.xx;

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

int main()
{
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v0 = { -0.3,-0.6 };
glm::vec2 v1 = { 0,0.7 };
glm::vec2 v2 = { 0.3,-0.6 };

v0.x = ((v0.x + 1) / 2) * 100;
v0.y = ((1 - v0.y) / 2) * 100;
v1.x = ((v1.x + 1) / 2) * 100;
v1.y = ((1 - v1.y) / 2) * 100;
v2.x = ((v2.x + 1) / 2) * 100;
v2.y = ((1 - v2.y) / 2) * 100;

float p2_w0 = edgeFunction(v1, v2, p2);
float p2_w1 = edgeFunction(v2, v0, p2);
float p2_w2 = edgeFunction(v0, v1, p2);

float p1_w0 = edgeFunction(v1, v2, p1);
float p1_w1 = edgeFunction(v2, v0, p1);
float p1_w2 = edgeFunction(v0, v1, p1);

glm::vec2 edge0 = v2 - v1;
glm::vec2 edge1 = v0 - v2;
glm::vec2 edge2 = v1 - v0;

bool inside_p1 = true;
bool inside_p2 = true;

inside_p1 &= (p1_w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (p1_w0 > 0));
inside_p1 &= (p1_w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (p1_w1 > 0));
inside_p1 &= (p1_w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (p1_w2 > 0));

inside_p2 &= (p2_w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (p2_w0 > 0));
inside_p2 &= (p2_w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (p2_w1 > 0));
inside_p2 &= (p2_w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (p2_w2 > 0));

std::cout << "(50,50) inside: " << std::boolalpha << inside_p1 << std::endl;

std::cout << "(90,50) inside: " << std::boolalpha << inside_p2 << std::endl;
return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return  ((c.x - a.x)* (b.y - a.y) - (c.y - a.y) * (b.x - a.x));
}

int main()
{
float width, height;

width = 100.0f;
height = 100.0f;

glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.0f, 0.7f);
glm::vec2 v2(0.3f, -0.6f);

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 a0, a1, a2;

a0.x = (v0.x + 1) / 2;
a0.y = (1 - v0.y) / 2;
a1.x = (v1.x + 1) / 2;
a1.y = (1 - v1.y) / 2;
a2.x = (v2.x + 1) / 2;
a2.y = (1 - v2.y) / 2;

v0.x = ((v0.x + 1) / 2) * width;
v0.y = ((1 - v0.y) / 2) * height;
v1.x = ((v1.x + 1) / 2) * width;
v1.y = ((1 - v1.y) / 2) * height;
v2.x = ((v2.x + 1) / 2) * width;
v2.y = ((1 - v2.y) / 2) * height;

float insidep11 = edgeFunction(v0, v1, p1);
float insidep12 = edgeFunction(v1, v2, p1);
float insidep13 = edgeFunction(v2, v0, p1);

bool p1inside;

if (insidep11 < 0 && insidep12 < 0 && insidep13 < 0) {
p1inside = true;
}
else p1inside = false;

float insidep21 = edgeFunction(v0, v1, p2);
float insidep22 = edgeFunction(v1, v2, p2);
float insidep23 = edgeFunction(v2, v0, p2);

bool p2inside;

if (insidep21 < 0 && insidep22 < 0 && insidep23 < 0) {
p2inside = true;
}
else p2inside = false;

std::cout << "(50,50) : " << std::boolalpha << p1inside << std::endl;
std::cout << "(90,50) : " << std::boolalpha << p2inside << std::endl;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{

return(c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);

}

int main() {
int width = 100, height = 100;

glm::vec2 v0 = { -0.3f, -0.6f };
glm::vec2 v1 = { 0, 0.7f };  //중요 포인트 : 2차원 3점을 이용함. 즉, 3차원이 아닌 투사 후의 2차원 점
glm::vec2 v2 = { 0.3f, -0.6f };

//raster
v0.x = (float)((v0.x + 1) / 2 * width);
v0.y = (float)((1 - v0.y) / 2 * height);

v1.x = (float)((v1.x + 1) / 2 * width);
v1.y = (float)((1 - v1.y) / 2 * height);

v2.x = (float)((v2.x + 1) / 2 * width);
v2.y = (float)((1 - v2.y) / 2 * height);

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

bool insidep1;
bool insidep2;

float p1_0 = edgeFunction(v0, v1, p1);
float p1_1 = edgeFunction(v1, v2, p1);
float p1_2 = edgeFunction(v2, v0, p1);

float p2_0 = edgeFunction(v0, v1, p2);
float p2_1 = edgeFunction(v1, v2, p2);
float p2_2 = edgeFunction(v2, v0, p2);

if (p1_0 > 0 && p1_1 > 0 && p1_2 > 0) {
insidep1 = true;
}
else
{
insidep1 = false;
}

if (p2_0 > 0 && p2_1 > 0 && p2_2 > 0) {
insidep2 = true;
}
else
{
insidep2 = false;
}

std::cout << "P1(50,50) inside? " << std::boolalpha << insidep1 << std::endl;
std::cout << "P2(90,50) inside? " << std::boolalpha << insidep2 << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtc/constants.hpp>
#define GLM_FORCE_SWIZZLE

using namespace glm;
using namespace std;

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

vec2 normalizedVec(vec2& a)
{
a.x = (a.x + 1) / 2;
a.y = (1 - a.y) / 2;
return a;
}
vec2 rasterVec(vec2& a)
{
a.x = a.x * 100;
a.y = a.y * 100;
return a;
}
int main()
{
int width = 100, height = 100;

vec2 v0 = { -0.3,-0.6 };
vec2 v1 = { 0,0.7 };
vec2 v2 = { 0.3,-0.6 };

vec2 p1 = { 50,50 };
vec2 p2 = { 90,50 };

v0 = normalizedVec(v0);
v1 = normalizedVec(v1);
v2 = normalizedVec(v2);

v0 = rasterVec(v0);
v1 = rasterVec(v1);
v2 = rasterVec(v2);

cout << "v0 레스터" << to_string(v0) << endl;
cout << "v1 레스터" << to_string(v1) << endl;
cout << "v2 레스터" << to_string(v2) << endl;

float w0 = edgeFunction(v0, v1, p1);
float w1 = edgeFunction(v1, v2, p1);
float w2 = edgeFunction(v2, v0, p1);

bool inside1 = (w0 > 0 && w1 > 0 && w2 > 0);

cout << "edgeFunction w0(v0,v1,p1) = " << w0 << endl;
cout << "edgeFunction w1(v1,v2,p1) = " << w1 << endl;
cout << "edgeFunction w2(v2,v0,p1) = " << w2 << endl;

if (inside1)
{
cout << "p1 : "<<inside1<< endl;
}
else
{
cout << "p1 : "<<inside1 << endl;
}

w0 = edgeFunction(v0, v1, p2);
w1 = edgeFunction(v1, v2, p2);
w2 = edgeFunction(v2, v0, p2);
bool inside2 = (w0 > 0 && w1 > 0 && w2 > 0);

cout << "edgeFunction w0(v0,v1,p2) = " << w0 << endl;
cout << "edgeFunction w1(v1,v2,p2) = " << w1 << endl;
cout << "edgeFunction w2(v2,v0,p2) = " << w2 << endl;

if (inside2)
{
cout << "p2 : "<<inside2 << endl;
}
else
{
cout << "p2 : "<<inside2 << endl;
}

}

# data[].attributes.body
#define GLM_FORCE_SWIZZLE

#include <iostream>
#include <glm/glm.hpp>
#include  <glm/gtx/string_cast.hpp>
#include <glm/mat4x4.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat3x2.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return(c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}

int main()
{
int width = 100, height = 100;

glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.0f, 0.7f);
glm::vec2 v2(0.3f, -0.6f);

v0.x = ((v0.x + 1) / 2) * width;
v0.y = ((1 - v0.y) / 2) * height;
v1.x = ((v1.x + 1) / 2) * width;
v1.y = ((1 - v1.y) / 2) * height;
v2.x = ((v2.x + 1) / 2) * width;
v2.y = ((1 - v2.y) / 2) * height;

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

bool insidep1 = (edgeFunction(v1, v0, p1) > 0) && (edgeFunction(v2, v1, p1) > 0) && (edgeFunction(v0, v2, p1) > 0);
bool insidep2 = (edgeFunction(v1, v0, p2) > 0) && (edgeFunction(v2, v1, p2) > 0) && (edgeFunction(v0, v2, p2) > 0);

std::cout << "(50,50) : " << std::boolalpha << insidep1 << std::endl;
std::cout << "(90,50) : " << std::boolalpha << insidep2 << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>

#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_SWIZZLE

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
glm::vec2 v0 = { -0.3f, -0.6f };
glm::vec2 v1 = { 0.0f, 0.7f };
glm::vec2 v2 = { 0.3f, -0.6f };
glm::vec2 p1 = { 50,50 };
glm::vec2 p2 = { 90,50 };

glm::vec2 v0Ndc, v1Ndc, v2Ndc;

v0Ndc.x = (v0.x + 1) / 2;
v0Ndc.y = (1 - v0.y) / 2;
v1Ndc.x = (v1.x + 1) / 2;
v1Ndc.y = (1 - v1.y) / 2;
v2Ndc.x = (v2.x + 1) / 2;
v2Ndc.y = (1 - v2.y) / 2;

glm::vec2 v0Ras,v1Ras,v2Ras;

v0Ras.x = (int)(v0Ndc.x * 100);
v0Ras.y = (int)(v0Ndc.x * 100);
v1Ras.x = (int)(v1Ndc.x * 100);
v1Ras.y = (int)(v1Ndc.x * 100);
v2Ras.x = (int)(v2Ndc.x * 100);
v2Ras.y = (int)(v2Ndc.x * 100);

if (v0Ras.x == 100) v0Ras.x = 100 - 1;
if (v0Ras.y == 100) v0Ras.y = 100 - 1;
if (v1Ras.x == 100) v1Ras.x = 100 - 1;
if (v1Ras.y == 100) v1Ras.y = 100 - 1;
if (v2Ras.x == 100) v2Ras.x = 100 - 1;
if (v2Ras.y == 100) v2Ras.y = 100 - 1;

float w0 = edgeFunction(v1Ras, v2Ras, p1);
float w1 = edgeFunction(v2Ras, v0Ras, p1);
float w2 = edgeFunction(v0Ras, v1Ras, p1);

float w3 = edgeFunction(v1Ras, v2Ras, p2);
float w4 = edgeFunction(v2Ras, v0Ras, p2);
float w5 = edgeFunction(v0Ras, v1Ras, p2);

bool overlaps;
if (w0 > 0 && w1 > 0 && w2 > 0)
overlaps = true;
else
overlaps = false;
std::cout << "{50,50}" << (overlaps == 1 ? "true" : "false") << std::endl;

if (w3 > 0 && w4 > 0 && w5 > 0)
overlaps = true;
else
overlaps = false;
std::cout << "{90,50}" << (overlaps == 1 ? "true" : "false") << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x));
}

int main()
{
int width = 100;
int height = 100;

glm::vec2 v0 = { -0.3, -0.6 };
glm::vec2 v1 = { 0, 0.7 };
glm::vec2 v2 = { 0.3, -0.6 };

glm::vec2 p1 = { 50, 50 };
glm::vec2 p2 = { 90, 50 };

//스크린 -> ndc

glm::vec2 nor_v0;
nor_v0.x = (v0.x + 1) / 2;
nor_v0.y = (1 - v0.y) / 2;

glm::vec2 nor_v1;
nor_v1.x = (v1.x + 1) / 2;
nor_v1.y = (1 - v1.y) / 2;

glm::vec2 nor_v2;
nor_v2.x = (v2.x + 1) / 2;
nor_v2.y = (1 - v2.y) / 2;

glm::ivec2 ras_v0;
ras_v0.x = (int)(nor_v0.x * width);
ras_v0.y = (int)(nor_v0.y * height);

glm::ivec2 ras_v1;
ras_v1.x = (int)(nor_v1.x * width);
ras_v1.y = (int)(nor_v1.y * height);

glm::ivec2 ras_v2;
ras_v2.x = (int)(nor_v2.x * width);
ras_v2.y = (int)(nor_v2.y * height);

float r0 = edgeFunction(ras_v0, ras_v2, p1);
float r1 = edgeFunction(ras_v2, ras_v1, p1);
float r2 = edgeFunction(ras_v1, ras_v0, p1);

std::cout << "p1에 대한 edgefunction 값" << std::endl;
std::cout << r0 << std::endl;
std::cout << r1 << std::endl;
std::cout << r2 << std::endl;

bool inside;
if
(r0 > 0 && r1 > 0 && r2 > 0) inside = true;
else
inside = false;
std::cout << "p1{50, 50}이 안에 있는가" << (inside == 1 ? "true" : "false") << std::endl;

float r0_ = edgeFunction(ras_v0, ras_v2, p2);
float r1_ = edgeFunction(ras_v2, ras_v1, p2);
float r2_ = edgeFunction(ras_v1, ras_v0, p2);

std::cout << "p2에 대한 edgefunction 값" << std::endl;
std::cout << r0_ << std::endl;
std::cout << r1_ << std::endl;
std::cout << r2_ << std::endl;

if (r0_ > 0 && r1_ > 0 && r2_ > 0)
inside = true;
else
inside = false;
std::cout << "p1{50, 50}이 안에 있는가" << (inside == 1 ? "true" : "false") << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

bool edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0, 0.7f);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 ndc_v0;
glm::vec2 ndc_v1;
glm::vec2 ndc_v2;

ndc_v0.x = (v0.x + 1) / 2;
ndc_v0.y = (1 - v0.y) / 2;

ndc_v1.x = (v1.x + 1) / 2;
ndc_v1.y = (1 - v1.y) / 2;

ndc_v2.x = (v2.x + 1) / 2;
ndc_v2.y = (1 - v2.y) / 2;

glm::vec2 raster_v0;
glm::vec2 raster_v1;
glm::vec2 raster_v2;

raster_v0.x = (int)(ndc_v0.x * 100);
raster_v0.y = (int)(ndc_v0.y * 100);
raster_v1.x = (int)(ndc_v1.x * 100);
raster_v1.y = (int)(ndc_v1.y * 100);
raster_v2.x = (int)(ndc_v2.x * 100);
raster_v2.y = (int)(ndc_v2.y * 100);

if (raster_v0.x == 100) raster_v0.x = 100 - 1;
if (raster_v0.y == 100) raster_v0.y = 100 - 1;
if (raster_v1.x == 100) raster_v1.x = 100 - 1;
if (raster_v1.y == 100) raster_v1.y = 100 - 1;
if (raster_v2.x == 100) raster_v2.x = 100 - 1;
if (raster_v2.y == 100) raster_v2.y = 100 - 1;

bool p1_w0 = edgeFunction(raster_v1, raster_v2, p1);
bool p1_w1 = edgeFunction(raster_v2, raster_v0, p1);
bool p1_w2 = edgeFunction(raster_v0, raster_v1, p1);

bool p2_w0 = edgeFunction(raster_v1, raster_v2, p2);
bool p2_w1 = edgeFunction(raster_v2, raster_v0, p2);
bool p2_w2 = edgeFunction(raster_v0, raster_v1, p2);

glm::vec2 edge0 = raster_v0 - raster_v1;
glm::vec2 edge1 = raster_v0 - raster_v0;
glm::vec2 edge2 = raster_v1 - raster_v0;

bool inside_P1 = true;
bool inside_P2 = true;

if (p1_w0 == true && p1_w1 == true && p1_w2 == true)
inside_P1 = true;
else
inside_P1 = false;

if (p2_w0 == true && p2_w1 == true && p2_w2 == true)
inside_P2 = true;
else
inside_P2 = false;

if (inside_P1)
std::cout << "p1 is inside" << std::endl;
else if (!inside_P1)
std::cout << "p1 is outside" << std::endl;

if (inside_P2)
std::cout << "p2 is inside" << std::endl;
else if (!inside_P2)
std::cout << "p2 is outside" << std::endl;
}

# data[].attributes.body
#include <iostream>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/gtx/string_cast.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}

glm::vec2 coordinateFunction(const glm::vec2 vec) {
int width = 100;
int height = 100;

glm::vec2 ndc_raster_vec;

ndc_raster_vec.x = (int)((vec.x + 1) / 2 * width);
ndc_raster_vec.y = (int)((1 - vec.y) / 2 * height);

if (ndc_raster_vec.x == width) ndc_raster_vec.x = width - 1;
if (ndc_raster_vec.y == height) ndc_raster_vec.y = height - 1;

return ndc_raster_vec;
}

int main() {
int width = 100;
int height = 100;

glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0.3, -0.6);
glm::vec2 v2(0, 0.7);

glm::vec2 v0_raster = coordinateFunction(v0);
glm::vec2 v1_raster = coordinateFunction(v1);
glm::vec2 v2_raster = coordinateFunction(v2);

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

float w01 = edgeFunction(v1_raster, v2_raster, p1);
float w11 = edgeFunction(v2_raster, v0_raster, p1);
float w21 = edgeFunction(v0_raster, v1_raster, p1);

float w02 = edgeFunction(v1_raster, v2_raster, p2);
float w12 = edgeFunction(v2_raster, v0_raster, p2);
float w22 = edgeFunction(v0_raster, v1_raster, p2);

glm::vec2 edge0 = v2 - v1;
glm::vec2 edge1 = v0 - v2;
glm::vec2 edge2 = v1 - v0;

std::cout << "v0_raster: " + to_string(v0_raster) << std::endl;
std::cout << "v1_raster: " + to_string(v1_raster) << std::endl;
std::cout << "v2_raster: " + to_string(v2_raster) << std::endl;

bool overlaps_p1 = true;
bool overlaps_p2 = true;

overlaps_p1 &= (w01 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w01 > 0));
overlaps_p1 &= (w11 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w11 > 0));
overlaps_p1 &= (w21 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w21 > 0));

overlaps_p2 &= (w02 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w02 > 0));
overlaps_p2 &= (w12 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w12 > 0));
overlaps_p2 &= (w22 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w22 > 0));

if (overlaps_p1) {
std::cout << "p1: 이 점은 내부에 있습니다." << std::endl;
}
else
std::cout << "p1: 이 점은 외부에 있습니다." << std::endl;

if (overlaps_p2) {
std::cout << "p2: 이 점은 내부에 있습니다." << std::endl;
}
else
std::cout << "p2: 이 점은 외부에 있습니다." << std::endl;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

inline float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return(c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}

int main()
{
glm::vec2 v0 = { -0.3, -0.6 };
glm::vec2 v1 = { 0, 0.7 };
glm::vec2 v2 = { 0.3, -0.6 };

glm::vec2 p1 = { 50, 50 };
glm::vec2 p2 = { 90, 50 };

int width = 100;
int height = 100;

v0.x = (v0.x + 1) / 2;
v0.y = (1 - v0.y) / 2;

v1.x = (v1.x + 1) / 2;
v1.y = (1 - v1.y) / 2;

v2.x = (v2.x + 1) / 2;
v2.y = (1 - v2.y) / 2;

glm::ivec2 v0_raster;
glm::ivec2 v1_raster;
glm::ivec2 v2_raster;

v0_raster.x = (int)(v0.x * width);
v0_raster.y = (int)(v0.y * height);
if (v0_raster.x == width) v0_raster.x = width - 1;
if (v0_raster.y == height) v0_raster.y = height - 1;

v1_raster.x = (int)(v1.x * width);
v1_raster.y = (int)(v1.y * height);
if (v1_raster.x == width) v1_raster.x = width - 1;
if (v1_raster.y == height) v1_raster.y = height - 1;

v2_raster.x = (int)(v2.x * width);
v2_raster.y = (int)(v2.y * height);
if (v2_raster.x == width) v2_raster.x = width - 1;
if (v2_raster.y == height) v2_raster.y = height - 1;

float z0 = edgeFunction(v0_raster, v1_raster, p1);
float z1 = edgeFunction(v1_raster, v2_raster, p1);
float z2 = edgeFunction(v2_raster, v0_raster, p1);

bool overlaps = true;
if (z0 > 0 && z1 > 0 && z2 > 0)
{
overlaps = true;
}
else if (z0 < 0 && z1 < 0 && z2 < 0)
{
overlaps = true;
}
else
{
overlaps = false;
}

std::cout << z0 << z1 << z2 << std::endl;

if (overlaps == true)
{
std::cout << "True" << std::endl;
}
else
{
std::cout << "False" << std::endl;
}

float w0 = edgeFunction(v1_raster, v2_raster, p2);
float w1 = edgeFunction(v2_raster, v0_raster, p2);
float w2 = edgeFunction(v0_raster, v1_raster, p2);

bool overlaps2 = true;

if (w0 > 0 && w1 > 0 && w2 > 0)
{
overlaps2 = true;
}
else
{
overlaps2 = false;
}

std::cout << w0 << w1 << w2 << std::endl;

if (overlaps2 == true)
{
std::cout << "True" << std::endl;
}
else
{
std::cout << "False" << std::endl;
}
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include  <glm/gtx/string_cast.hpp>

using namespace std;

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return { (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]) };
}

int main() {
int width = 100;
int height = 100;

glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0, 0.7);
glm::vec2 v2(0.3, -0.6);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v_0 = { (v0.x + 1) / 2, (1 - v0.y) / 2 };
glm::vec2 v_1 = { (v1.x + 1) / 2, (1 - v1.y) / 2 };
glm::vec2 v_2 = { (v2.x + 1) / 2, (1 - v2.y) / 2 };

glm::ivec2 v_0r = { (int)((v_0.x) * width), (int)((v_0.y) * height) };
glm::ivec2 v_1r = { (int)((v_1.x) * width), (int)((v_1.y) * height) };
glm::ivec2 v_2r = { (int)((v_2.x) * width), (int)((v_2.y) * height) };

float w0 = edgeFunction(v_1r, v_0r, p1);
float w1 = edgeFunction(v_2r, v_1r, p1);
float w2 = edgeFunction(v_0r, v_2r, p1);

float w_0 = edgeFunction(v_1r, v_0r, p2);
float w_1 = edgeFunction(v_2r, v_1r, p2);
float w_2 = edgeFunction(v_0r, v_2r, p2);

if (w0 >= 0 && w1 >= 0 && w2 >= 0) {
cout << "(50,50) : " << "inside" << endl;
}
else
{
cout << "(50,50) : " << "outside" << endl;
}

if (w_0 >= 0 && w_1 >= 0 && w_2 >= 0) {
cout << "(90,50) : " << "inside" << endl;
}
else
{
cout << "(90,50) : " << "outside" << endl;
}
return 0;
}

# data[].attributes.body
#include<iostream>
#include<glm/glm.hpp>
#include<glm/gtx/string_cast.hpp>
#include<glm/gtx/transform.hpp>
#include<glm/gtx/matrix_transform_2d.hpp>
#include<stdio.h>

#define GLM_FORCE_SWIZZLE

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c);
glm::vec2 GetRaster(glm::vec2 v);

int width = 100;
int height = 100;

int main()
{

glm::vec2 v0 = glm::vec2(-0.3, -0.6);
glm::vec2 v1 = glm::vec2(0, 0.7);
glm::vec2 v2 = glm::vec2(0.3, -0.6);

glm::vec2 p1 = glm::vec2(50, 50);
glm::vec2 p2 = glm::vec2(90, 50);

glm::vec2 v0Raster = GetRaster(v0);
glm::vec2 v1Raster = GetRaster(v1);
glm::vec2 v2Raster = GetRaster(v2);

std::cout << "v0 레스터라이저: " << glm::to_string(v0Raster) << std::endl;
std::cout << "v1 레스터라이저: " << glm::to_string(v1Raster) << std::endl;
std::cout << "v2 레스터라이저: " << glm::to_string(v2Raster) << std::endl;

bool check1 = true;
bool check2 = true;
bool check3 = true;
if (edgeFunction(v0Raster, v1Raster, p1) < 0)
check1 = false;
if (edgeFunction(v1Raster, v2Raster, p1) < 0)
check2 = false;
if (edgeFunction(v2Raster, v0Raster, p1) < 0)
check3 = false;

if (check1 && check2 && check3)
std::cout << "p1은 안에 있음." << std::endl;
else
std::cout << "p1은 밖에 있음." << std::endl;

check1 = true;
check2 = true;
check3 = true;

if (edgeFunction(v0Raster, v1Raster, p2) < 0)
check1 = false;
if (edgeFunction(v1Raster, v2Raster, p2) < 0)
check2 = false;
if (edgeFunction(v2Raster, v0Raster, p2) < 0)
check3 = false;

if (check1 && check2 && check3)
std::cout << "p2는 안에 있음." << std::endl;
else
std::cout << "p2는 밖에 있음." << std::endl;

return 0;
}

glm::vec2 GetRaster(glm::vec2 v)
{
glm::vec2 P_proj_nor = glm::vec2(0,0);

P_proj_nor.x = (v.x + 1) / 2;
P_proj_nor.y = (1 - v.y) / 2;

glm::vec2 P_proj_raster = glm::vec2(0, 0);

P_proj_raster.x = (int)(P_proj_nor.x * width);
P_proj_raster.y = (int)(P_proj_nor.y * height);
if (P_proj_raster.x == width) P_proj_raster.x = width - 1;
if (P_proj_raster.y == height) P_proj_raster.y = height - 1;

return P_proj_raster;
}

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/mat4x4.hpp>
#include <glm/mat3x3.hpp>
#include <glm/mat2x2.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

//#define GLM_ENABLE_EXPERIMENTAL
#define GLM_FORCE_SWIZZLE

const double DEGREES_TO_RADIANS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();

bool edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
int width = 100;
int height = 100;
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0.0f, 0.7f);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v0nor;
glm::vec2 v1nor;
glm::vec2 v2nor;

v0nor.x = (v0.x + 1) / 2;
v0nor.y = (1 - v0.y) / 2;

v1nor.x = (v1.x + 1) / 2;
v1nor.y = (1 - v1.y) / 2;

v2nor.x = (v2.x + 1) / 2;
v2nor.y = (1 - v2.y) / 2;

glm::vec2 v0ras;
glm::vec2 v1ras;
glm::vec2 v2ras;

v0ras.x = (int)(v0nor.x * width);
v0ras.y = (int)(v0nor.y * height);

v1ras.x = (int)(v1nor.x * width);
v1ras.y = (int)(v1nor.y * height);

v2ras.x = (int)(v2nor.x * width);
v2ras.y = (int)(v2nor.y * height);

if (v0ras.x == width)  v0ras.x = width  - 1;
if (v0ras.y == height)v0ras.y = height - 1;

if (v1ras.x == width)  v1ras.x = width - 1;
if (v1ras.y == height) v1ras.y = height - 1;

if (v2ras.x == width)  v2ras.x = width - 1;
if (v2ras.y == height) v2ras.y = height - 1;

bool w0_1 = edgeFunction(v1ras, v2ras, p1);
bool w1_1 = edgeFunction(v2ras, v0ras, p1);
bool w2_1 = edgeFunction(v0ras, v1ras, p1);
bool w0_2 = edgeFunction(v1ras, v2ras, p2);
bool w1_2 = edgeFunction(v2ras, v0ras, p2);
bool w2_2 = edgeFunction(v0ras, v1ras, p2);

bool inp1,inp2;

if (w0_1 == true && w1_1 == true && w2_1 == true)
std::cout << "(50,50) : inside" << std::endl;
else
std::cout << "(50,50) : outside" << std::endl;

if (w0_2 == true && w1_2 == true && w2_2 == true)
std::cout << "(90,50) : inside" << std::endl;
else
std::cout << "(90,50) : outside" << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/mat4x4.hpp>
#include <glm/mat2x2.hpp>
#include <glm/mat3x2.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

bool edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) > 0);
}

float edgeFunctionF(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return(c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x);
}

int main()
{
glm::vec2 v = { -0.3, -0.6 };
glm::vec2 v1 = { 0, 0.7 };
glm::vec2 v2 = { 0.3, -0.6 };

glm::vec2 P1 = { 50, 50 };
glm::vec2 P2 = { 90, 50 };

const uint32_t w = 100;
const uint32_t h = 100;

glm::vec2 V;
V.x = (v.x + 1) / 2;
V.y = (1 - v.y) / 2;
glm::vec2 V1;
V1.x = (v1.x + 1) / 2;
V1.y = (1 - v1.y) / 2;
glm::vec2 V2;
V2.x = (v2.x + 1) / 2;
V2.y = (1 - v2.y) / 2;

glm::vec2 a;
a.x = (int)(V.x * w);
a.y = (int)(V.y * h);
if (a.x == w) a.x = w - 1;
if (a.y == h) a.y = h - 1;

glm::vec2 b;
b.x = (int)(V1.x * w);
b.y = (int)(V1.y * h);
if (b.x == w) b.x = w - 1;
if (b.y == h) b.y = h - 1;

glm::vec2 c;
c.x = (int)(V2.x * w);
c.y = (int)(V2.y * h);
if (c.x == w) c.x = w - 1;
if (c.y == h) c.y = h - 1;

bool w0 = edgeFunction(b, a, P1);
bool w1 = edgeFunction(c, b, P1);
bool w2 = edgeFunction(a, c, P1);

bool x0 = edgeFunction(b, a, P2);
bool x1 = edgeFunction(c, b, P2);
bool x2 = edgeFunction(a, c, P2);

bool _P1;
bool _P2;

if (w0 == true && w1 == true && w2 == true)
{
_P1 = true;
}
else {
_P1 = false;
}

if (x0 == true && x1 == true && x2 == true)
{
_P2 = true;
}
else
{
_P2 = false;
}

if (_P1 == true) {
std::cout << "P1(50,50) is inside" << std::endl;
}
else if (_P1 == false) {
std::cout << "P1(50,50) is outside" << std::endl;
}

if (_P2 == true) {
std::cout << "P2(90,50) is inside" << std::endl;
}
else if (_P2 == false) {
std::cout << "P2(90,50) is outside" << std::endl;
}

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c) {
return(c[0] - a[0])* (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}

int main() {
int width = 100, height = 100; //이미지 해상도

glm::vec3 p1(50, 50, 0); // 포인트 1
glm::vec3 p2(90, 50, 0); // 포인트 2

// screen space
glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0.3, -0.6);
glm::vec2 v2(0, 0.7);

// ndc + raster
glm::vec2 _v0, _v1, _v2;
_v0.x = ((v0.x + 1) / 2) * 100;
_v0.y = ((1 - v0.y) / 2) * 100;
_v1.x = ((v1.x + 1) / 2) * 100;
_v1.y = ((1 - v1.y) / 2) * 100;
_v2.x = ((v2.x + 1) / 2) * 100;
_v2.y = ((1 - v2.y) / 2) * 100;

if (_v0.x == width)
_v0.x = width - 1;
if (_v0.y == height)
_v0.y = height - 1;
if (_v1.x == width)
_v1.x = width - 1;
if (_v1.y == height)
_v1.y = height - 1;
if (_v2.x == width)
_v2.x = width - 1;
if (v2.y == height)
v2.y = height - 1;

bool inside1, inside2;

float p1_w0 = edgeFunction(_v1, _v2, p1);
float p1_w1 = edgeFunction(_v2, _v0, p1);
float p1_w2 = edgeFunction(_v0, _v1, p1);
if (p1_w0 > 0 && p1_w1 > 0 && p1_w2 > 0)
inside1 = true;
else inside1 = false;
std::cout << "P1 is inside? = ";
if (inside1)
std::cout << "true";
else
std::cout << "false";

float p2_w0 = edgeFunction(_v1, _v2, p2);
float p2_w1 = edgeFunction(_v2, _v0, p2);
float p2_w2 = edgeFunction(_v0, _v1, p2);
if (p2_w0 > 0 && p2_w1 > 0 && p2_w2 > 0)
inside2 = true;
else inside2 = false;
std::cout << "\nP2 is inside? = ";
if (inside2)
std::cout << "true";
else
std::cout << "false";

return 0;
}

# data[].attributes.body
#define GLM_ENABLE_EXPERIMENTAL

#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

glm::vec2 screen_to_raster(const glm::vec2& v, int width, int height)
{
glm::vec2 result;
result.x = (int)(((v.x + 1) / 2) * width);
result.y = (int)(((1 - v.y) / 2) * height);

return result;
}

glm::vec2 screen_to_ndc(glm::vec2& v)
{
glm::vec2 result;
result.x = (v.x + 1) / 2;
result.y = (v.y + 1) / 2;
return result;
}

glm::vec2 ndc_to_raster(const glm::vec2& v, int w, int h)
{
glm::vec2 result;
result.x = v.x * w;
result.y = -1 * v.y * h;
return result;
}

bool edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
if (a.y >= 0)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}
else
{
return (-(c.x - a.x) * (b.y - a.y) + (-c.y - a.y) * (b.x - a.x) >= 0);
}
}

bool is_inside(const glm::vec2& v0, const glm::vec2& v1, const glm::vec2& v2, const glm::vec2& p)
{
float w0 = edgeFunction(v1, v2, p);
float w1 = edgeFunction(v2, v0, p);
float w2 = edgeFunction(v0, v1, p);
std::cout << "" << w0 << ", " << w1 << ", " << w2 << "\n ";
glm::vec2 edge0 = v2 - v1;
glm::vec2 edge1 = v0 - v2;
glm::vec2 edge2 = v1 - v0;

bool inside = true;
inside &= edgeFunction(v0, v1, p);
inside &= edgeFunction(v1, v2, p);
inside &= edgeFunction(v2, v0, p);
return inside;
}

int main()
{
const int width = 100, height = 100;

glm::vec2 v0 = { -0.3f, -0.6f };
glm::vec2 v1 = { 0.f, 0.7f };
glm::vec2 v2 = { 0.3f, -0.6f };

glm::vec2 p1 = { 50,50 };
glm::vec2 p2 = { 90,50 };

v0 = screen_to_ndc(v0);
v1 = screen_to_ndc(v1);
v2 = screen_to_ndc(v2);

v0 = ndc_to_raster(v0, width, height);
v1 = ndc_to_raster(v1, width, height);
v2 = ndc_to_raster(v2, width, height);

bool is_p1_inside = is_inside(v0, v1, v2, p1);

if (is_p1_inside)
{
std::cout << "p1 overlaps the triangle\n";
}
else
{
std::cout << "p1 doesn't overlaps the triangle\n";
}

bool is_p2_inside = is_inside(v0, v1, v2, p2);

if (is_p2_inside)
{
std::cout << "p2 overlaps the triangle\n";
}
else
{
std::cout << "p2 doesn't overlaps the triangle\n";
}
return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
float myWidth = (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
//std::cout << myWidth << std::endl;
return myWidth;
}

int main()
{
int width = 100;
int height = 100;
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0.0f, 0.7f);

v0.x = ((v0.x + 1) / 2) * 100;
v0.y = ((1 - v0.y) / 2) * 100;
if (v0.x == width) v0.x = width - 1;
if (v0.y == height) v0.y = height - 1;

v1.x = ((v1.x + 1) / 2) * 100;
v1.y = ((1 - v1.y) / 2) * 100;
if (v1.x == width) v1.x = width - 1;
if (v1.y == height) v1.y = height - 1;

v2.x = ((v2.x + 1) / 2) * 100;
v2.y = ((1 - v2.y) / 2) * 100;
if (v2.x == width) v2.x = width - 1;
if (v2.y == height) v2.y = height - 1;

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

bool insidep1 = (edgeFunction(v0, v1, p1) > 0) && (edgeFunction(v1, v2, p1) > 0) && (edgeFunction(v2, v0, p1) > 0);
bool insidep2 = (edgeFunction(v0, v1, p2) > 0) && (edgeFunction(v1, v2, p2) > 0) && (edgeFunction(v2, v0, p2) > 0);

//std::cout << v0.x << ", " << v0.y << std::endl;
//std::cout << v1.x << ", " << v1.y << std::endl;
//std::cout << v2.x << ", " << v2.y << std::endl;
std::cout << "(50,50) inside: " << std::boolalpha << insidep1 << std::endl;
std::cout << "(90,50) inside: " << std::boolalpha << insidep2 << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtc/constants.hpp>
#define GLM_FORCE_SWIZZLE
const double DEGREES_TO_RADIAS = glm::pi<float>() / 180.0;
const double RADIANS_TO_DEGREES = 180.0 / glm::pi<float>();
#define Wighth 100
#define Herght 100

using namespace glm;
using namespace std;

vec2 normallized_(vec2& _vec)
{
_vec.x = (_vec.x + 1) / 2;
_vec.y = ( 1 -_vec.y ) / 2;
return _vec;
}

vec2 rester_space(vec2& _vec)
{
_vec.x = _vec.x * Wighth;
_vec.y = _vec.y * Herght;
return _vec;
}

bool edgeFunction(vec2 a, vec2 b, vec2 c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
vec2 p1 = { 50,50 };
vec2 p2 = { 90,50 };

vec2 v0 = { -0.3f, -0.6f };
vec2 v1 = { 0, 0.7f };
vec2 v2 = { 0.3f, -0.6f };

v0 = normallized_(v0);
v1 = normallized_(v1);
v2 = normallized_(v2);

v0 = rester_space(v0);
v1 = rester_space(v1);
v2 = rester_space(v2);

float ev_0 = edgeFunction(v2, v1, p1);
float ev_1 = edgeFunction(v0, v2, p1);
float ev_2 = edgeFunction(v1, v0, p1);

float ev_11 = edgeFunction(v2, v1, p2);
float ev_12 = edgeFunction(v0, v2, p2);
float ev_13 = edgeFunction(v1, v0, p2);

vec2 edge0 = v1 - v2;
vec2 edge1 = v2 - v1;
vec2 edge2 = v0 - v1;

bool isoverlaps1 = true;
bool isoverlaps2 = true;

cout << " ev_0 : " << ev_0 << " \n";
cout << " ev_1 : " << ev_1 << " \n";
cout << " ev_2 : " << ev_2 << " \n";

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트,

isoverlaps1 &= (ev_0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (ev_0 > 0));
isoverlaps1 &= (ev_1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (ev_1 > 0));
isoverlaps1 &= (ev_1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (ev_2 > 0));

isoverlaps2 &= (ev_11 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (ev_11 > 0));
isoverlaps2 &= (ev_12 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (ev_12 > 0));
isoverlaps2 &= (ev_12 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (ev_13 > 0));

cout << " P1 : " << isoverlaps1 << " \n";

cout << " P2 : " << isoverlaps2 << " \n";

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>

using namespace std;

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) >= 0);
}

int main()
{
float width = 100.0f;
float height = 100.0f;

glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.0f, 0.7f);
glm::vec2 v2(0.3f, -0.6f);

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v_r0;
glm::vec2 v_r1;
glm::vec2 v_r2;

v_r0.x = (int)(((v0.x + 1) / 2) * width);
v_r0.y = (int)(((1 - v0.y) / 2) * height);

v_r1.x = (int)(((v1.x + 1) / 2) * width);
v_r1.y = (int)(((1 - v1.y) / 2) * height);

v_r2.x = (int)(((v2.x + 1) / 2) * width);
v_r2.y = (int)(((1 - v2.y) / 2) * height);

if (v_r0.x == width)  v_r0.x = width - 1;
if (v_r0.y == height) v_r0.y = height - 1;

if (v_r1.x == width)  v_r1.x = width - 1;
if (v_r1.y == height) v_r1.y = height - 1;

if (v_r2.x == width)  v_r2.x = width - 1;
if (v_r2.y == height) v_r2.y = height - 1;

float w0_1 = edgeFunction(v_r1, v_r0, p1);
float w1_1 = edgeFunction(v_r2, v_r1, p1);
float w2_1 = edgeFunction(v_r0, v_r2, p1);
float w0_2 = edgeFunction(v_r1, v_r0, p2);
float w1_2 = edgeFunction(v_r2, v_r1, p2);
float w2_2 = edgeFunction(v_r0, v_r2, p2);

if (w0_1 == true && w1_1 == true && w2_1 == true)
std::cout << "(50,50) : inside" << std::endl;
else
std::cout << "(50,50) : outside" << std::endl;

if (w0_2 == true && w1_2 == true && w2_2 == true)
std::cout << "(90,50) : inside" << std::endl;
else
std::cout << "(90,50) : outside" << std::endl;

return 0;
};

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <glm/gtx/string_cast.hpp>

glm::vec2 ScreenToNDC(glm::vec2 v);
glm::vec2 NDCToRaster(glm::vec2 v, int width, int height);
float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c);
using namespace std;
int main()
{
int width = 100;
int height = 100;

glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0.3, -0.6);
glm::vec2 v2(0, 0.7);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

//NDC------------------------------------------------------------
v0 = ScreenToNDC(v0);
v1 = ScreenToNDC(v1);
v2 = ScreenToNDC(v2);
//raster-----------------------------------------------------------
v0 = NDCToRaster(v0, width, height);
v1 = NDCToRaster(v1, width, height);
v2 = NDCToRaster(v2, width, height);

cout << glm::to_string(v0) << endl << glm::to_string(v1) << endl << glm::to_string(v2) << endl;
//-----------------------------------------------------------------

float w0 = edgeFunction(v2,v1, p1);
float w1 = edgeFunction(v1, v0, p1);
float w2 = edgeFunction(v0, v2, p1);

float _w0 = edgeFunction(v2, v1, p2);
float _w1 = edgeFunction(v1, v0, p2);
float _w2 = edgeFunction(v0, v2, p2);

bool isP1 = true;
bool isP2 = true;

if (w0 > 0 && w1 > 0 && w2 > 0)
isP1 = true;
else
isP1 = false;

if (_w0 > 0 && _w1 > 0 && _w2 > 0)
isP2 = true;
else
isP2 = false;

if (isP1)
std::cout << "p1 is inside" << std::endl;
else if (!isP1)
std::cout << "p1 is outside" << std::endl;

if (isP2)
std::cout << "p2 is inside" << std::endl;
else if (!isP2)
std::cout << "p2 is outside" << std::endl;

return 0;
}

glm::vec2 ScreenToNDC(glm::vec2 v)
{
glm::vec2 nor;
nor.x = (v.x + 1) * 0.5f;
nor.y = (1- v.y) * 0.5f;

return nor;
}

glm::vec2 NDCToRaster(glm::vec2 v, int width, int height)
{
glm::vec2 raster;

raster.x = (int)(v.x * width);
raster.y = (int)(v.y * height);

if (raster.x == width)
raster.x = width - 1;
if (raster.y == height)
raster.y = height - 1;

return raster;
}

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return(c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>
#include <glm/gtx/string_cast.hpp>

glm::vec2 normal(glm::vec2 vTemp);
glm::vec2 raster(glm::vec2 vTemp, int width, int height);
float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c);
bool isInside(glm::vec2 v0, glm::vec2 v1, glm::vec2 v2, glm::vec2 p);

using namespace std;
int main()
{
glm::vec2 v0(-0.3, -0.6);
glm::vec2 v1(0, 0.7);
glm::vec2 v2(0.3, -0.6);

v0 = normal(v0);
v1 = normal(v1);
v2 = normal(v2);

v0 = raster(v0, 100, 100);
v1 = raster(v1, 100, 100);
v2 = raster(v2, 100, 100);

cout << glm::to_string(v0) << endl << glm::to_string(v1) << endl << glm::to_string(v2) << endl;

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

cout << "p1 is ";
isInside(v0, v1, v2, p1) ? cout << "Inside" << endl : cout << "outside" << endl;

cout << "p2 is ";
isInside(v0, v1, v2, p2) ? cout << "Inside" << endl : cout << "outside" << endl;

return 0;
}

bool isInside(glm::vec2 v0, glm::vec2 v1, glm::vec2 v2, glm::vec2 p)
{
float w0 = edgeFunction(v1, v0, p);
float w1 = edgeFunction(v2, v1, p);
float w2 = edgeFunction(v0, v2, p);

glm::vec2 edge0 = v0 - v1;
glm::vec2 edge1 = v1 - v2;
glm::vec2 edge2 = v2 - v0;

bool overlaps = true;

overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1 > 0));
overlaps &= (w2 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2 > 0));

return overlaps;
}

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
}

glm::vec2 normal(glm::vec2 vTemp)
{
glm::vec2 nor;
nor.x = (vTemp.x + 1) / 2;
nor.y = (1 - vTemp.y) / 2;

return nor;
}

glm::vec2 raster(glm::vec2 vTemp, int width, int height)
{
glm::vec2 ras;
ras.x = (int)(vTemp.x * width);
ras.y = (int)(vTemp.y * height);

return ras;

}

# data[].attributes.body
#define GLM_FORCE_SWIZZLE

#include <stdio.h>
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/mat4x4.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}
int main()
{
int width = 100, height = 100;

glm::vec2 v0 = { -0.3,-0.6 };
glm::vec2 v1 = { 0,0.7 };
glm::vec2 v2 = { 0.3,-0.6};
glm::vec2 p1 = { 50, 50 };
glm::vec2 p2 = { 90, 50 };

glm::vec2 ndcv0 = {(v0.x + 1) / 2 , (1-v0.y)/2};
glm::vec2 ndcv1 = { (v1.x + 1) / 2 , (1 - v1.y) / 2 };
glm::vec2 ndcv2 = { (v2.x + 1) / 2 , (1 - v2.y) / 2 };

glm::vec2 rasterv0 = { int(ndcv0.x * width), int(ndcv0.y * height) };
glm::vec2 rasterv1 = { int(ndcv1.x * width), int(ndcv1.y * height) };
glm::vec2 rasterv2 = { int(ndcv2.x * width), int(ndcv2.y * height) };

if (rasterv0.x == width) rasterv0.x = width - 1;
if (rasterv0.y == height)rasterv0.y = height - 1;
if (rasterv1.x == width) rasterv1.x = width - 1;
if (rasterv1.y == height)rasterv1.y = height - 1;
if (rasterv2.x == width) rasterv2.x = width - 1;
if (rasterv2.y == height)rasterv2.y = height - 1;

float w0 = edgeFunction(rasterv0, rasterv1, p1);
float w1 = edgeFunction(rasterv1, rasterv2, p1);
float w2 = edgeFunction(rasterv2, rasterv0, p1);

float w3 = edgeFunction(rasterv0, rasterv1, p2);
float w4 = edgeFunction(rasterv1, rasterv2, p2);
float w5 = edgeFunction(rasterv2, rasterv0, p2);

bool inside = true;
if (w0 > 0 && w1 > 0 && w2 > 0)
inside = true;
else
inside = false;

printf("p1\n");

if (inside == true) {
printf("inside = true\n");
}
else if (inside == false) {
printf("inside = false\n");
}

bool inside2 = true;
if (w3 > 0 && w4 > 0 && w5 > 0)
inside2 = true;
else
inside2 = false;

printf("p2\n");

if (inside2 == true) {
printf("inside = true\n");
}
else if (inside2 == false) {
printf("inside = false\n");
}
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include  <glm/gtx/string_cast.hpp>

int main()
{
int width = 100;
int height = 100;
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0.0f, 0.7f);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v0nor;
glm::vec2 v1nor;
glm::vec2 v2nor;

v0nor.x = (v0.x + 1) / 2;
v0nor.y = (1 - v0.y) / 2;

v1nor.x = (v1.x + 1) / 2;
v1nor.y = (1 - v1.y) / 2;

v2nor.x = (v2.x + 1) / 2;
v2nor.y = (1 - v2.y) / 2;

glm::vec2 v0ras;
glm::vec2 v1ras;
glm::vec2 v2ras;

v0ras.x = (int)(v0nor.x * width);
v0ras.y = (int)(v0nor.y * height);

v1ras.x = (int)(v1nor.x * width);
v1ras.y = (int)(v1nor.y * height);

v2ras.x = (int)(v2nor.x * width);
v2ras.y = (int)(v2nor.y * height);

if (v0ras.x == width)  v0ras.x = width  - 1;
if (v0ras.y == height)v0ras.y = height - 1;

if (v1ras.x == width)  v1ras.x = width - 1;
if (v1ras.y == height) v1ras.y = height - 1;

if (v2ras.x == width)  v2ras.x = width - 1;
if (v2ras.y == height) v2ras.y = height - 1;

bool w0_1 = edgeFunction(v1ras, v2ras, p1);
bool w1_1 = edgeFunction(v2ras, v0ras, p1);
bool w2_1 = edgeFunction(v0ras, v1ras, p1);
bool w0_2 = edgeFunction(v1ras, v2ras, p2);
bool w1_2 = edgeFunction(v2ras, v0ras, p2);
bool w2_2 = edgeFunction(v0ras, v1ras, p2);

bool inp1,inp2;

if (w0_1 == true && w1_1 == true && w2_1 == true)
std::cout << "(50,50) : inside" << std::endl;
else
std::cout << "(50,50) : outside" << std::endl;

if (w0_2 == true && w1_2 == true && w2_2 == true)
std::cout << "(90,50) : inside" << std::endl;
else
std::cout << "(90,50) : outside" << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

int main()
{
int width = 100, height = 100;

glm::vec2 v0 = { -0.3f, -0.6f };
glm::vec2 v1 = { 0.0f, 0.7f };
glm::vec2 v2 = {0.3f, -0.6f};

glm::vec2 p1 = { 50, 50 };
glm::vec2 p2 = { 90, 50 };

v0.x = ((v0.x + 1) / 2) * width;
v0.y = ((1 - v0.y) / 2) * height;
v1.x = ((v1.x + 1) / 2) * width;
v1.y = ((1 - v1.y) / 2) * height;
v2.x = ((v2.x + 1) / 2) * width;
v2.y = ((1 - v2.y) / 2) * height;

float w0 = edgeFunction(v1, v2, p1);
float w1 = edgeFunction(v2, v0, p1);
float w2 = edgeFunction(v0, v1, p1);

float w0_2 = edgeFunction(v1, v2, p2);
float w1_2 = edgeFunction(v2, v0, p2);
float w2_2 = edgeFunction(v0, v1, p2);

glm::vec2 edge0 = v2 - v1;
glm::vec2 edge1 = v0 - v2;
glm::vec2 edge2 = v1 - v0;

bool overlaps1 = true;
bool overlaps2 = true;

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트,
//
overlaps1 &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
overlaps1 &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1 > 0));
overlaps1 &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2 > 0));

overlaps2 &= (w0_2 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0_2 > 0));
overlaps2 &= (w1_2 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1_2 > 0));
overlaps2 &= (w1_2 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2_2 > 0));

if (overlaps1) {
std::cout << "p1은 내부에 존재" << std::endl;
}
else std::cout << "p1은 외부에 존재" << std::endl;

if (overlaps2) {
std::cout << "p2은 내부에 존재" << std::endl;
}
else std::cout << "p2은 외부에 존재" << std::endl;

return 0;
}

# data[].attributes.body
using namespace glm;
using namespace std;

int w = 100, h = 100;

vec2 Raster(vec2& a)
{
a.x = ((a.x + 1) / 2)*w;
a.y = ((1-a.y) / 2)*h; //방향이 반대이기 때문엔 1-a.y 해야함

if (a.x == w)a.x = w - 1;
if (a.y == h)a.x = h - 1;

return a;
}

bool EdgeFunction(const vec2& a, const vec2& b, const vec2& c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) <= 0);// y축이 음수이기 때문에 0과 같거나 0보다 적음
}

string Iftrue(bool a)//안,밖 표시
{
if (a == 1)
{
return "true, inside";
}
else
{
return "false, outside";
}
}

int main()
{
vec2 v0 = { -0.3,-0.6 };
vec2 v1 = { 0,0.7 };
vec2 v2 = { 0.3,-0.6 };

vec2 P1 = { 50,50 };
vec2 P2 = { 90,50 };

v0 = Raster(v0);
v1 = Raster(v1);
v2 = Raster(v2);

float w0 = EdgeFunction(v1, v2, P1);
float w1 = EdgeFunction(v2, v0, P1);
float w2 = EdgeFunction(v0, v1, P1);

float m0 = EdgeFunction(v1, v2, P2);
float m1 = EdgeFunction(v2, v0, P2);
float m2 = EdgeFunction(v0, v1, P2);

float  area= EdgeFunction(v0, v1, v2);

vec2 edge0 = v2 - v1;
vec2 edge1 = v0 - v2;
vec2 edge2 = v1 - v0;

bool overlaps = true;

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트//
overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1 > 0));
overlaps &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2 > 0));

cout << "P1:" << Iftrue(overlaps) << endl;

overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (m0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (m1 > 0));
overlaps &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (m2 > 0));

cout << "P2:" << Iftrue(overlaps) << endl;
}

# data[].attributes.body
#include <glm/glm.hpp>
#include <glm/gtx/string_cast.hpp >
#include <iostream>

using namespace std;
using namespace glm;

#define WIDTH 100
#define HEIGHT 100

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
return (c[0] - a[0]) * (a[1] - b[1]) - (a[1] - c[1]) * (b[0] - a[0]);
}

int main()
{
//값
/*int width = 100;
int height = 100;*/

vec2 v0 = {-0.3f, -0.6f};
vec2 v1 = {0.0f, 0.7f};
vec2 v2 = {0.3f, -0.6f};

vec2 p1 = {50, 50};
vec2 p2 = {90, 50};

bool overlaps1 = true;
bool overlaps2 = true;

// screen space coordinates 에서 NDC(normalized device coordinates)로 변환
v0.x = ((v0.x + 1) / 2) * WIDTH;
v0.y = ((1 - v0.y) / 2) * HEIGHT;
v1.x = ((v1.x + 1) / 2) * WIDTH;
v1.y = ((1 - v1.y) / 2) * HEIGHT;
v2.x = ((v2.x + 1) / 2) * WIDTH;
v2.y = ((1 - v2.y) / 2) * HEIGHT;

// edgeFunction
float p1_w0 = edgeFunction(v1, v2, p1);
float p1_w1 = edgeFunction(v2, v0, p1);
float p1_w2 = edgeFunction(v0, v1, p1);

float p2_w0 = edgeFunction(v1, v2, p2);
float p2_w1 = edgeFunction(v2, v0, p2);
float p2_w2 = edgeFunction(v0, v1, p2);

vec2 edge0 = v2 - v1;
vec2 edge1 = v0 - v2;
vec2 edge2 = v1 - v0;

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트
overlaps1 &= (p1_w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (p1_w0 > 0));
overlaps1 &= (p1_w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (p1_w1 > 0));
overlaps1 &= (p1_w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (p1_w2 > 0));

overlaps2 &= (p2_w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (p2_w0 > 0));
overlaps2 &= (p2_w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (p2_w1 > 0));
overlaps2 &= (p2_w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (p2_w2 > 0));

// 출력
if (overlaps1) cout << "p1 Inside" << std::endl;
else cout << "p1 Outside" << std::endl;
if (overlaps2) cout << "p2 Inside" << std::endl;
else cout << "p2 Outside" << std::endl;

return 0;

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include  <glm/gtx/string_cast.hpp>

int main()
{
int width = 100;
int height = 100;
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0.0f, 0.7f);
glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

glm::vec2 v0nor;
glm::vec2 v1nor;
glm::vec2 v2nor;

v0nor.x = (v0.x + 1) / 2;
v0nor.y = (1 - v0.y) / 2;

v1nor.x = (v1.x + 1) / 2;
v1nor.y = (1 - v1.y) / 2;

v2nor.x = (v2.x + 1) / 2;
v2nor.y = (1 - v2.y) / 2;

glm::vec2 v0ras;
glm::vec2 v1ras;
glm::vec2 v2ras;

v0ras.x = (int)(v0nor.x * width);
v0ras.y = (int)(v0nor.y * height);

v1ras.x = (int)(v1nor.x * width);
v1ras.y = (int)(v1nor.y * height);

v2ras.x = (int)(v2nor.x * width);
v2ras.y = (int)(v2nor.y * height);

if (v0ras.x == width)  v0ras.x = width  - 1;
if (v0ras.y == height)v0ras.y = height - 1;

if (v1ras.x == width)  v1ras.x = width - 1;
if (v1ras.y == height) v1ras.y = height - 1;

if (v2ras.x == width)  v2ras.x = width - 1;
if (v2ras.y == height) v2ras.y = height - 1;

bool w0_1 = edgeFunction(v1ras, v2ras, p1);
bool w1_1 = edgeFunction(v2ras, v0ras, p1);
bool w2_1 = edgeFunction(v0ras, v1ras, p1);
bool w0_2 = edgeFunction(v1ras, v2ras, p2);
bool w1_2 = edgeFunction(v2ras, v0ras, p2);
bool w2_2 = edgeFunction(v0ras, v1ras, p2);

bool inp1,inp2;

if (w0_1 == true && w1_1 == true && w2_1 == true)
std::cout << "(50,50) : inside" << std::endl;
else
std::cout << "(50,50) : outside" << std::endl;

if (w0_2 == true && w1_2 == true && w2_2 == true)
std::cout << "(90,50) : inside" << std::endl;
else
std::cout << "(90,50) : outside" << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/vec2.hpp>

float edgeFunction(const glm::vec2& a, const glm::vec2& b, const glm::vec2& c)
{
float resultWidth = (c[0] - a[0]) * (b[1] - a[1]) - (c[1] - a[1]) * (b[0] - a[0]);
return resultWidth;
}

int main()
{
int width = 100;
int height = 100;
glm::vec2 v0(-0.3f, -0.6f);
glm::vec2 v1(0.3f, -0.6f);
glm::vec2 v2(0.0f, 0.7f);

v0.x = ((v0.x + 1))/2 * width;
v0.y = ((1 - v0.y))/2 * height;
if (v0.x == width)v0.x = width - 1;
if (v0.y == height)v0.y = height - 1;

v1.x = ((v1.x + 1))/2 * width;
v1.y = ((1 - v1.y))/2 * height;
if (v1.x == width)v1.x = width - 1;
if (v1.y == height)v1.y = height - 1;

v2.x = ((v2.x + 1))/2 * width;
v2.y = ((1 - v2.y))/2 * height;
if (v2.x == width)v2.x = width - 1;
if (v2.y == height)v2.y = height - 1;

glm::vec2 p1(50, 50);
glm::vec2 p2(90, 50);

bool insidep1 = (edgeFunction(v0, v1, p1) > 0) && (edgeFunction(v1, v2, p1) > 0) && (edgeFunction(v2, v0, p1) > 0);
bool insidep2 = (edgeFunction(v0, v1, p2) > 0) && (edgeFunction(v1, v2, p2) > 0) && (edgeFunction(v2, v0, p2) > 0);

std::cout << "(50,50) inside: " << std::boolalpha << insidep1 << std::endl;
std::cout << "(90,50) inside: " << std::boolalpha << insidep2 << std::endl;

return 0;
}

# data[].attributes.body
#include <iostream>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include  <glm/gtx/string_cast.hpp>

using namespace glm;
using namespace std;

int w = 100, h = 100;

vec2 Raster(vec2& a)
{
a.x = ((a.x + 1) / 2) * w;
a.y = ((1 - a.y) / 2) * h; //방향이 반대이기 때문엔 1-a.y 해야함

if (a.x == w)a.x = w - 1;
if (a.y == h)a.x = h - 1;

return a;
}

bool EdgeFunction(const vec2& a, const vec2& b, const vec2& c)
{
return ((c.x - a.x) * (b.y - a.y) - (c.y - a.y) * (b.x - a.x) <= 0);// y축이 음수이기 때문에 0과 같거나 0보다 적음
}

string Iftrue(bool a)//안,밖 표시
{
if (a == 1)
{
return "true = inside";
}
else
{
return "false = outside";
}
}

int main()
{
vec2 v0 = { -0.3,-0.6 };
vec2 v1 = { 0,0.7 };
vec2 v2 = { 0.3,-0.6 };

vec2 P1 = { 50,50 };
vec2 P2 = { 90,50 };

v0 = Raster(v0);
v1 = Raster(v1);
v2 = Raster(v2);

float w0 = EdgeFunction(v1, v2, P1);
float w1 = EdgeFunction(v2, v0, P1);
float w2 = EdgeFunction(v0, v1, P1);

float m0 = EdgeFunction(v1, v2, P2);
float m1 = EdgeFunction(v2, v0, P2);
float m2 = EdgeFunction(v0, v1, P2);

float  area = EdgeFunction(v0, v1, v2);

vec2 edge0 = v2 - v1;
vec2 edge1 = v0 - v2;
vec2 edge2 = v1 - v0;

bool overlaps = true;

// 포인트가 edge 상에 있는지, 오른쪽 왼쪽인지 테스트//
overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (w0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (w1 > 0));
overlaps &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (w2 > 0));

cout << "P1: \n" << Iftrue(overlaps) << endl;

overlaps &= (w0 == 0 ? ((edge0.y == 0 && edge0.x > 0) || edge0.y > 0) : (m0 > 0));
overlaps &= (w1 == 0 ? ((edge1.y == 0 && edge1.x > 0) || edge1.y > 0) : (m1 > 0));
overlaps &= (w1 == 0 ? ((edge2.y == 0 && edge2.x > 0) || edge2.y > 0) : (m2 > 0));

cout << "P2: \n" << Iftrue(overlaps) << endl;
}