Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Collision - F - Linear.c
    »Keywords«  Collision;Linear;Line;Ray;Segment;Point;Distance;Closest
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/*   -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
      following conditions are met:
        Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
        Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
          provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

/* ==== Linear - Point ================================================================================================================================================== */

/*                                                                                                                                                                        */
/*  Segment Definition: G0(α) = P0 + α•D0 | α ε [ 0, 1]                                                                                                                   */
/*                                                                                                                                                                        */
/* Derivation:                                                                                                                                                            */
/*  Let the points of closest contact be Q0 = P0+γ•D0, and v = P1-Q0                                                                                                      */
/*  Geometrically we know that the vector connecting the two closest points of contact ( or the minimal distance vector ) must be perpendicular to the line.              */
/*  Thus, D0•v=0, D1•v=0, DS=P1-P0, v=P1-(P0+γ•D0)                                                                                                                        */
/*                                                                                                                                                                        */
/*      0 = D0_(P1-P0-γ•D0,DIM)                                                                                                                                           */
/*      0 = D0_(DS-γ•D0,DIM)                                                                                                                                              */
/*      0 = D0•DS-γ•D0•D0                                                                                                                                                 */
/*      γ = D0•DS / D0•D0                                                                                                                                                 */
/*                                                                                                                                                                        */
/* However, we know that γ ε [ 0, 1], generating three cases:                                                                                                             */
/*                                                                                                                                                                        */
/* [1] γ ε (-∞, 0) || γ = 0                                                                                                                                               */
/*    Distance: The distance between P0 and P1                                                                                                                            */
/*       = (P1-P0)T_(P1-P0,DIM)                                                                                                                                           */
/*       = DS•DS                                                                                                                                                          */
/*                                                                                                                                                                        */
/* [2] γ ε [ 0, 1] || γ = (DS•D0) / (D0•D0)                                                                                                                               */
/*    Distance: The distance value would be || v ||.                                                                                                                      */
/*       = || v || = v•v = (DS-γ•D0)T_(DS-γ•D0,DIM)                                                                                                                       */
/*       = DS•DS + γ•γ•D0•D0 - 2•γ•DS•D0                                                                                                                                  */
/*       = DS•DS + γ_(γ•D0•D0 - 2•DS•D0,DIM)                                                                                                                              */
/*       = DS•DS + γ_((DS•D0 / D0•D0,DIM)•D0•D0 - 2•DS•D0)                                                                                                                */
/*       = DS•DS + γ_(DS•D0 - 2•DS•D0,DIM)                                                                                                                                */
/*       = DS•DS - γ_(DS•D0,DIM)                                                                                                                                          */
/*                                                                                                                                                                        */
/* [3] γ ε ( 1, ∞) || γ = 1                                                                                                                                               */
/*    Distance: The distance between P0+D0 and P1                                                                                                                         */
/*       = (P1-P0-D0)T_(P1-P0-D0,DIM)                                                                                                                                     */
/*       = (DS-D0)T_(DS-D0,DIM)                                                                                                                                           */
/*       = DS•DS - 2•DS•D0 + D0•D0                                                                                                                                        */
/*                                                                                                                                                                        */
/* == Collision ========================================================================================================================================================= */

/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define TYPE TgFLOAT32
#define MKL(A) A##F
#define F(A) A##_F32
#define V(A) A##_F32_04

#define LN_CAP_0 0
#define LN_CAP_1 0
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR00_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR00_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR00_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#define LN_CAP_0 1
#define LN_CAP_1 0
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR10_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR10_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR10_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#define LN_CAP_0 1
#define LN_CAP_1 1
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR11_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR11_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR11_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#undef V
#undef F
#undef MKL
#undef TYPE 


/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */

#define TYPE TgFLOAT64
#define MKL(A) A
#define F(A) A##_F64
#define V(A) A##_F64_04

#define LN_CAP_0 0
#define LN_CAP_1 0
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR00_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR00_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR00_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#define LN_CAP_0 1
#define LN_CAP_1 0
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR10_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR10_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR10_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#define LN_CAP_0 1
#define LN_CAP_1 1
    #define LN_CAP_2 0
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR11_##B##_LR00)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 0
    #define VPM(A,B) V(A##_LR11_##B##_LR10)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2

    #define LN_CAP_2 1
    #define LN_CAP_3 1
    #define VPM(A,B) V(A##_LR11_##B##_LR11)
    #include "TgS Collision - F - Linear-Linear.c_inc"
    #undef VPM
    #undef LN_CAP_3
    #undef LN_CAP_2
#undef LN_CAP_1
#undef LN_CAP_0

#undef V
#undef F
#undef MKL
#undef TYPE


/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */