Raised This Month: $51 Target: $400
 12% 

how to? point c intersects line created by points a and b?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Skyy
AlliedModders Donor
Join Date: Jan 2010
Location: Toronto, Canada
Old 11-18-2017 , 08:10   how to? point c intersects line created by points a and b?
Reply With Quote #1

Sorry, I'm not sure if sourcemod has a function for this, and if it does if anyone can point me to the api related to it. Thanks!
Skyy is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-18-2017 , 20:17   Re: how to? point c intersects line created by points a and b?
Reply With Quote #2

SM doesn't provide a function to tell you if three points are collinear, if that's what you're asking. If you need help implementing one, Google will definitely provide many samples in other languages.
Fyren is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 11-19-2017 , 00:49   Re: how to? point c intersects line created by points a and b?
Reply With Quote #3

Don't think sourcemod has anything for this, but as Fyren suggested you can use some basic maths to implement it yourself. Off the top of my head you can use some slope formulas to see if slope of AC is same as AB, and if they are then they all lie on same line.
hmmmmm is offline
Kryptanyte
Junior Member
Join Date: Dec 2015
Old 11-19-2017 , 03:34   Re: how to? point c intersects line created by points a and b?
Reply With Quote #4

You could use something like this which I think is a bit simpler than what hmmmmm suggested.

PHP Code:
stock bool IsPointOnLine(float a[3], float b[3], float c[3])
{
    return (
GetVectorDistance(a,c) + GetVectorDistance(b,c)) == GetVectorDistance(a,b);

Kryptanyte is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 11-19-2017 , 06:07   Re: how to? point c intersects line created by points a and b?
Reply With Quote #5

Quote:
Originally Posted by Kryptanyte View Post
You could use something like this which I think is a bit simpler than what hmmmmm suggested.

PHP Code:
stock bool IsPointOnLine(float a[3], float b[3], float c[3])
{
    return (
GetVectorDistance(a,c) + GetVectorDistance(b,c)) == GetVectorDistance(a,b);

Two floating point values that are a product of some arithmetic operation will almost never be exactly equal. You should check if those two are nearly equal.
klippy is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 11-21-2017 , 23:38   Re: how to? point c intersects line created by points a and b?
Reply With Quote #6

I think this is the most efficient way to solve this

THIS WILL GIVE ERRONEOUS VALUES FOR COMBINATIONS LIKE {0.0, 1.0, 1.0} {0.0, 1.0, 2.0} {0.0, 1.0, 1.5}

PHP Code:
stock bool IsPointOnLine(const float a[3], const float b[3], const float c[3], float precision 0.0001)
{
    
float ab[3]; MakeVectorFromPoints(abab);
    
float ac[3]; MakeVectorFromPoints(acac);
    
    
// If a and c reside on the same point, lambda won't be a real number 
    // (no real number multiplied by zero will give you a non-zero result)
    
if (FloatNearlyEqual(a[0], c[0], precision) && FloatNearlyEqual(a[1], c[1], precision) && FloatNearlyEqual(a[2], c[2], precision))
    {
        return 
true;
    }
    
    
// If all lambdas are equal, there is a real lambda that turns ab into ac
    // assuming that lambda_ac is 1
    
float lambda_x ab[0] / ac[0];
    
float lambda_y ab[1] / ac[1];
    
float lambda_z ab[2] / ac[2];
    return 
FloatNearlyEqual(lambda_xlambda_yprecision) && FloatNearlyEqual(lambda_ylambda_zprecision);
}

stock bool FloatNearlyEqual(float xfloat y float precision 0.0001)
{
    return 
FloatAbs) < precision;

__________________

Last edited by fakuivan; 12-03-2017 at 15:13.
fakuivan is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 11-21-2017 , 23:46   Re: how to? point c intersects line created by points a and b?
Reply With Quote #7

I'm not sure why you're using the FloatDiv and FloatCompare functions, but it makes your code much more confusing.

e.g. FloatDiv(x, y) == x / y
!FloatCompare(x, y) == x < y

Last edited by hmmmmm; 11-21-2017 at 23:48.
hmmmmm is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 11-22-2017 , 00:34   Re: how to? point c intersects line created by points a and b?
Reply With Quote #8

Quote:
Originally Posted by hmmmmm View Post
I'm not sure why you're using the FloatDiv and FloatCompare functions, but it makes your code much more confusing.

e.g. FloatDiv(x, y) == x / y
!FloatCompare(x, y) == x < y
Unless those are overloads (they are) I don't think those operators work the same for int and float.
__________________

Last edited by fakuivan; 11-22-2017 at 00:50.
fakuivan is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode