NetSim Source Code Help
Loading...
Searching...
No Matches
Geometry.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#include "main.h"
25#include "Mobility.h"
26
29 NetSim_COORDINATES* intersect)
30{
31 double s02_x, s02_y, s10_x, s10_y, s32_x, s32_y, s_numer, t_numer, denom, t;
32 s10_x = q1->X - p1->X;
33 s10_y = q1->Y - p1->Y;
34 s32_x = q2->X - p2->X;
35 s32_y = q2->Y - p2->Y;
36
37 denom = s10_x * s32_y - s32_x * s10_y;
38 if (denom == 0)
39 return false; // Collinear
40 bool denomPositive = denom > 0;
41
42 s02_x = p1->X - p2->X;
43 s02_y = p1->Y - p2->Y;
44 s_numer = s10_x * s02_y - s10_y * s02_x;
45
46 if ((s_numer < 0) == denomPositive)
47 return false; // No collision
48
49 t_numer = s32_x * s02_y - s32_y * s02_x;
50 if ((t_numer < 0) == denomPositive)
51 return false; // No collision
52
53 if (((s_numer > denom) == denomPositive) || ((t_numer > denom) == denomPositive))
54 return false; // No collision
55
56 // Collision detected
57 t = t_numer / denom;
58 if (intersect)
59 intersect->X = p1->X + (t * s10_x);
60 if (intersect)
61 intersect->Y = p1->Y + (t * s10_y);
62
63 return true;
64}
bool fnMobility_findIntersect(NetSim_COORDINATES *p1, NetSim_COORDINATES *q1, NetSim_COORDINATES *p2, NetSim_COORDINATES *q2, NetSim_COORDINATES *intersect)
Definition: Geometry.c:27
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41