1f220fa62Smrg/* 2f220fa62Smrg** License Applicability. Except to the extent portions of this file are 3f220fa62Smrg** made subject to an alternative license as permitted in the SGI Free 4f220fa62Smrg** Software License B, Version 1.1 (the "License"), the contents of this 5f220fa62Smrg** file are subject only to the provisions of the License. You may not use 6f220fa62Smrg** this file except in compliance with the License. You may obtain a copy 7f220fa62Smrg** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 8f220fa62Smrg** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: 9f220fa62Smrg** 10f220fa62Smrg** http://oss.sgi.com/projects/FreeB 11f220fa62Smrg** 12f220fa62Smrg** Note that, as provided in the License, the Software is distributed on an 13f220fa62Smrg** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS 14f220fa62Smrg** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND 15f220fa62Smrg** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A 16f220fa62Smrg** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. 17f220fa62Smrg** 18f220fa62Smrg** Original Code. The Original Code is: OpenGL Sample Implementation, 19f220fa62Smrg** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, 20f220fa62Smrg** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. 21f220fa62Smrg** Copyright in any portions created by third parties is as indicated 22f220fa62Smrg** elsewhere herein. All Rights Reserved. 23f220fa62Smrg** 24f220fa62Smrg** Additional Notice Provisions: The application programming interfaces 25f220fa62Smrg** established by SGI in conjunction with the Original Code are The 26f220fa62Smrg** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released 27f220fa62Smrg** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version 28f220fa62Smrg** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X 29f220fa62Smrg** Window System(R) (Version 1.3), released October 19, 1998. This software 30f220fa62Smrg** was created using the OpenGL(R) version 1.2.1 Sample Implementation 31f220fa62Smrg** published by SGI, but has not been independently verified as being 32f220fa62Smrg** compliant with the OpenGL(R) version 1.2.1 Specification. 33f220fa62Smrg** 34f220fa62Smrg*/ 35f220fa62Smrg/* 36f220fa62Smrg*/ 37f220fa62Smrg 38f220fa62Smrg#include <stdlib.h> 39f220fa62Smrg#include <stdio.h> 40f220fa62Smrg 41f220fa62Smrg#include "polyUtil.h" 42f220fa62Smrg 43f220fa62SmrgReal area(Real A[2], Real B[2], Real C[2]) 44f220fa62Smrg{ 45f220fa62Smrg Real Bx, By, Cx, Cy; 46f220fa62Smrg Bx = B[0] - A[0]; 47f220fa62Smrg By = B[1] - A[1]; 48f220fa62Smrg Cx = C[0] - A[0]; 49f220fa62Smrg Cy = C[1] - A[1]; 50f220fa62Smrg return Bx*Cy - Cx*By; 51f220fa62Smrg 52f220fa62Smrg/* return (B[0]-A[0])*(C[1]-A[1]) - (C[0]-A[0])*(B[1]-A[1]);*/ 53f220fa62Smrg} 54f220fa62Smrg 55f220fa62Smrg/*given a directed line A->B, and a point P, 56f220fa62Smrg *determine whether P is to the left of AB. 57f220fa62Smrg *the line A->B (imagine it has beedn extended both 58f220fa62Smrg *end to the infinity) divides the plan into two 59f220fa62Smrg *half planes. When we walk from A to B, one 60f220fa62Smrg *half is to the left and the other half is to the right. 61f220fa62Smrg *return 1 if P is to the left. 62f220fa62Smrg *if P is on AB, 0 is returned. 63f220fa62Smrg */ 64f220fa62SmrgInt pointLeftLine(Real A[2], Real B[2], Real P[2]) 65f220fa62Smrg{ 66f220fa62Smrg if(area(A, B, P) >0) return 1; 67f220fa62Smrg else return 0; 68f220fa62Smrg} 69f220fa62Smrg 70f220fa62Smrg/*given two directed line: A -> B -> C, and another point P. 71f220fa62Smrg *determine whether P is to the left hand side of A->B->C. 72f220fa62Smrg *Think of BA and BC extended as two rays. So that the plane is 73f220fa62Smrg * divided into two parts. One part is to the left we walk from A 74f220fa62Smrg *to B and to C, the other part is to the right. 75f220fa62Smrg * In order for P to be the left, P must be either to the left 76f220fa62Smrg *of 77f220fa62Smrg */ 78f220fa62SmrgInt pointLeft2Lines(Real A[2], Real B[2], Real C[2], Real P[2]) 79f220fa62Smrg{ 80f220fa62Smrg Int C_left_AB = (area(A, B, C)>0); 81f220fa62Smrg Int P_left_AB = (area(A, B, P)>0); 82f220fa62Smrg Int P_left_BC = (area(B, C, P)>0); 83f220fa62Smrg 84f220fa62Smrg if(C_left_AB) 85f220fa62Smrg { 86f220fa62Smrg return (P_left_AB && P_left_BC); 87f220fa62Smrg } 88f220fa62Smrg else 89f220fa62Smrg return (P_left_AB || P_left_BC); 90f220fa62Smrg} 91