📄 inside.c
字号:
/* Copyright (c) Colorado School of Mines, 2006.*//* All rights reserved. *//*********************** self documentation **********************//*****************************************************************************INSIDE - Is a vertex or point inside a circum circle, etc. of a triangulated modelinCircum determine whether or not a vertex is inside a circum circleinCircumTri determine whether or not a vertex is inside a circum circle of a trianglein3Vertices determine whether or not a vertex is inside triangle (v1,v2,v3)inTri determine whether or not a vertex is inside a triangle ******************************************************************************Function Prototypes:int inCircum (float x, float y, float xc, float yc, float rs);int inCircumTri (float x, float y, Tri *t);int in3Vertices (float x, float y, Vertex *v1, Vertex *v2, Vertex *v3);int inTri (float x, float y, Tri *t);******************************************************************************inCircum:Input:x x-coordinate of vertexy y-coordinate of vertexxc x-coordinate of center of circumcircleyc y-coordinate of center of circumcirclers radius^2 of circumcircleReturns:1 if x,y inside of circumcircle0 otherwiseNotes:A vertex exactly on the edge of a circumcircle is taken as being outsideinCircumTri:Input:x x-coordinate of vertexy y-coordinate of vertext pointer to TriReturns:1 if x,y inside of circumcircle of a triangle0 otherwiseNotes:A vertex exactly on the edge of a circumcircle is taken as being outsidein3Vertices:Input:x x-coordinate of vertexy y-coordinate of vertexv1 pointer to first Vertexv2 pointer to second Vertexv3 pointer to third VertexReturns:1 if x,y inside of v1,v2,v30 otherwiseNotes:A vertex exactly on an edge of the triangle is taken as being insideinTri:Input:x x-coordinate of vertexy y-coordinate of vertext pointer to TriReturns:1 if x,y inside a triangle0 otherwiseNotes:A vertex exactly on the edge of a triangle is inside******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/04/91*****************************************************************************//**************** end self doc ********************************/#include "Triangles/triP.h"int inCircum (float x, float y, float xc, float yc, float rs)/*****************************************************************************inCircum - determine whether or not a vertex is inside a circum circle******************************************************************************Input:x x-coordinate of vertexy y-coordinate of vertexxc x-coordinate of center of circumcircleyc y-coordinate of center of circumcirclers radius^2 of circumcircleReturns:1 if x,y inside of circumcircle0 otherwise******************************************************************************Notes:A vertex exactly on the edge of a circumcircle is taken as being outside******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/04/91*****************************************************************************/{ float d,ds; if (rs==TRI_INFINITY) return(1); d = xc-x; ds = d*d; if (ds>=rs) return(0); else { d = yc-y; ds += d*d; if (ds>=rs) return(0); } return(1);}int inCircumTri (float x, float y, Tri *t)/*****************************************************************************inCircumTri - determine whether or not a vertex is inside a circum circle of a triangle******************************************************************************Input:x x-coordinate of vertexy y-coordinate of vertext pointer to TriReturns:1 if x,y inside of circumcircle of a triangle0 otherwise******************************************************************************Notes:A vertex exactly on the edge of a circumcircle is taken as being outside******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/04/91*****************************************************************************/{ return inCircum(x,y,t->xc,t->yc,t->rs);}int in3Vertices (float x, float y, Vertex *v1, Vertex *v2, Vertex *v3)/*****************************************************************************in3Vertices - determine whether or not a vertex is inside triangle (v1,v2,v3)******************************************************************************Input:x x-coordinate of vertexy y-coordinate of vertexv1 pointer to first Vertexv2 pointer to second Vertexv3 pointer to third VertexReturns:1 if x,y inside of v1,v2,v30 otherwise******************************************************************************Notes:A vertex exactly on an edge of the triangle is taken as being inside******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/04/91*****************************************************************************/{ float s1,s2,s3; float x1,y1,x2,y2,x3,y3; x1 = v1->x; y1 = v1->y; x2 = v2->x; y2 = v2->y; x3 = v3->x; y3 = v3->y; s1 = (x-x1)*(y2-y1)-(x2-x1)*(y-y1); s2 = (x-x2)*(y3-y2)-(x3-x2)*(y-y2); if (s1*s2<=0) return 0; s3 = (x-x3)*(y1-y3)-(x1-x3)*(y-y3); if (s2*s3<=0 || s1*s3<=0) return 0; return 1;}int inTri (float x, float y, Tri *t)/*****************************************************************************inTri - determine whether or not a vertex is inside a triangle******************************************************************************Input:x x-coordinate of vertexy y-coordinate of vertext pointer to TriReturns:1 if x,y inside a triangle0 otherwise******************************************************************************Notes:A vertex exactly on the edge of a triangle is inside******************************************************************************Author: Dave Hale, Colorado School of Mines, 06/04/91*****************************************************************************/{ Vertex *v1,*v2,*v3; v1 = t->eu->vu->v; v2 = t->eu->euCW->vu->v; v3 = t->eu->euCCW->vu->v; return in3Vertices(x,y,v1,v2,v3);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -