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

Distance between two lines


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 09-26-2012 , 19:08   Distance between two lines
Reply With Quote #1

I've tried to find such thing in the forum and I would not able to find something to answer my question, at least I've found this(http://forums.alliedmods.net/showpos...28&postcount=2) and it's useful at least, but it's close of what I want.

I wanted to check with a math code (welcome, not my speciality) the "distance" between two lines on the game, for being accurate, 2 players and 2 objects flying on air, both players owns one of these entities, and I wanted to check (by think forward) if one of these objects intersects with anyother's player object, a virtual collision, to be specific, to check if it crosses anyother's players invisible line to it's flying object, I'm not sure if I spelled it right what i've tried to say, but would be nice to see some math art in action here n.n

Anyway, thanks in advance!
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 09-26-2012 , 19:24   Re: Distance between two lines
Reply With Quote #2

I have an idea of what you want but I am in doubt. You could put a picture to understand.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 09-26-2012 at 19:24.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-27-2012 , 01:25   Re: Distance between two lines
Reply With Quote #3

Try this :

PHP Code:
Float:lines_distance(Float:flPoint1[3], Float:vecDir1[3], Float:flPoint2[3], Float:vecDir2[3])
{
    
xs_vec_normalize(vecDir1vecDir1)
    
xs_vec_normalize(vecDir2vecDir2)
    if( 
xs_vec_equal(vecDir1vecDir2) )
    {
        new 
Float:vecPoint1Point2[3]
        
xs_vec_sub(flPoint2flPoint1vecPoint1Point2)
        
        new 
Float:vecDirCross[3]
        
xs_vec_cross(vecPoint1Point2vecDir1vecDirCross)
        
        return 
xs_vec_len(vecDirCross) / xs_vec_len(vecDir1)
    }

    new 
Float:vecPoint1Point2[3]
    
xs_vec_sub(flPoint2flPoint1vecPoint1Point2)
    
    new 
Float:vecDirCross[3]
    
xs_vec_cross(vecDir1vecDir2vecDirCross)

    return 
floatabsdet3(vecPoint1Point2vecDir1vecDir2) ) / xs_vec_len(vecDirCross)
}

Float:det3Float:vec0[3] , Float:vec1[3] , Float:vec2[3] )
{
    return ( 
vec0[0]*vec1[1]*vec2[2] + vec1[0]*vec2[1]*vec0[2] + vec2[0]*vec0[1]*vec1[2] - vec0[0]*vec2[1]*vec1[2] - vec1[0]*vec0[1]*vec2[2] - vec2[0]*vec1[1]*vec0[2] )

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 09-27-2012 at 01:25.
ConnorMcLeod is offline
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 09-27-2012 , 19:09   Re: Distance between two lines
Reply With Quote #4

Quote:
Originally Posted by ConnorMcLeod View Post
Try this :

PHP Code:
Float:lines_distance(Float:flPoint1[3], Float:vecDir1[3], Float:flPoint2[3], Float:vecDir2[3])
{
    
xs_vec_normalize(vecDir1vecDir1)
    
xs_vec_normalize(vecDir2vecDir2)
    if( 
xs_vec_equal(vecDir1vecDir2) )
    {
        new 
Float:vecPoint1Point2[3]
        
xs_vec_sub(flPoint2flPoint1vecPoint1Point2)
        
        new 
Float:vecDirCross[3]
        
xs_vec_cross(vecPoint1Point2vecDir1vecDirCross)
        
        return 
xs_vec_len(vecDirCross) / xs_vec_len(vecDir1)
    }

    new 
Float:vecPoint1Point2[3]
    
xs_vec_sub(flPoint2flPoint1vecPoint1Point2)
    
    new 
Float:vecDirCross[3]
    
xs_vec_cross(vecDir1vecDir2vecDirCross)

    return 
floatabsdet3(vecPoint1Point2vecDir1vecDir2) ) / xs_vec_len(vecDirCross)
}

Float:det3Float:vec0[3] , Float:vec1[3] , Float:vec2[3] )
{
    return ( 
vec0[0]*vec1[1]*vec2[2] + vec1[0]*vec2[1]*vec0[2] + vec2[0]*vec0[1]*vec1[2] - vec0[0]*vec2[1]*vec1[2] - vec1[0]*vec0[1]*vec2[2] - vec2[0]*vec1[1]*vec0[2] )

The bad thing is that I need to pass a direction instead of another position, there exists a possibility for making it with and start pos and a end post for both?
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 09-28-2012 , 12:24   Re: Distance between two lines
Reply With Quote #5

If I am right, this should be fine.

PHP Code:
Float:lines_distance(Float:flLine1Point1[3], Float:flLine1Point2[3], Float:flLine2Point1[3], Float:flLine2Point2[3]) 

    new 
Float:vecDir1[3], Float:vecDir2[3]
    
    
xs_vec_sub(flLine1Point1flLine1Point2vecDir1)
    
xs_vec_sub(flLine2Point1flLine2Point2vecDir2)
    
    
xs_vec_normalize(vecDir1vecDir1
    
xs_vec_normalize(vecDir2vecDir2
    
    new 
Float:vecLine1Line2[3
    
xs_vec_sub(flLine2Point1flLine1Point1vecLine1Line2)
    
    if(
xs_vec_equal(vecDir1vecDir2)) 
    {         
        new 
Float:vecDirCross[3
        
xs_vec_cross(vecLine1Line2vecDir1vecDirCross
        
        return 
xs_vec_len(vecDirCross) / xs_vec_len(vecDir1
    } 
    
    new 
Float:vecDirCross[3
    
xs_vec_cross(vecDir1vecDir2vecDirCross

    return 
xs_vec_mul_escalar2(vecLine1Line2vecDirCross) / xs_vec_len(vecDirCross)
}

xs_vec_mul_escalar2(Float:vec1[], Float:vec2[])
{
    return 
vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2]

__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 09-28-2012 at 18:23.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 09-29-2012 , 15:41   Re: Distance between two lines
Reply With Quote #6

Quote:
Originally Posted by gladius View Post
If I am right, this should be fine.

PHP Code:
Float:lines_distance(Float:flLine1Point1[3], Float:flLine1Point2[3], Float:flLine2Point1[3], Float:flLine2Point2[3]) 

    new 
Float:vecDir1[3], Float:vecDir2[3]
    
    
xs_vec_sub(flLine1Point1flLine1Point2vecDir1)
    
xs_vec_sub(flLine2Point1flLine2Point2vecDir2)
    
    
xs_vec_normalize(vecDir1vecDir1
    
xs_vec_normalize(vecDir2vecDir2
    
    new 
Float:vecLine1Line2[3
    
xs_vec_sub(flLine2Point1flLine1Point1vecLine1Line2)
    
    if(
xs_vec_equal(vecDir1vecDir2)) 
    {         
        new 
Float:vecDirCross[3
        
xs_vec_cross(vecLine1Line2vecDir1vecDirCross
        
        return 
xs_vec_len(vecDirCross) / xs_vec_len(vecDir1
    } 
    
    new 
Float:vecDirCross[3
    
xs_vec_cross(vecDir1vecDir2vecDirCross

    return 
xs_vec_mul_escalar2(vecLine1Line2vecDirCross) / xs_vec_len(vecDirCross)
}

xs_vec_mul_escalar2(Float:vec1[], Float:vec2[])
{
    return 
vec1[0] * vec2[0] + vec1[1] * vec2[1] + vec1[2] * vec2[2]

As from I see you're getting the direction between these 2 points and that can result in a true statement when 2 lines can "intersect only when extended" but not as this real length, or i'm just saying bullshit? haha
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 09-29-2012 , 16:08   Re: Distance between two lines
Reply With Quote #7

I am getting director vector from two points in one line and getting director vector from two lines.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).

gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 10-01-2012 , 17:02   Re: Distance between two lines
Reply With Quote #8

Put a drawing about what you need.

You write the distance between 2 lines, so you have to get 2 vectors and get the difference. The result will be a vector (vector - vector = vector). If you want a distance in units, just get the lenght of the resulting vector.

Remember that 2 lines will not always be parallel. If you wan't distance between 2 "always parallel" lines, then it's fair easy to get it but it's the same principle.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 10-01-2012 , 17:48   Re: Distance between two lines
Reply With Quote #9

Quote:
Originally Posted by joropito View Post
Put a drawing about what you need.

You write the distance between 2 lines, so you have to get 2 vectors and get the difference. The result will be a vector (vector - vector = vector). If you want a distance in units, just get the lenght of the resulting vector.

Remember that 2 lines will not always be parallel. If you wan't distance between 2 "always parallel" lines, then it's fair easy to get it but it's the same principle.
Two lines are parallel if their direction vectors are equal.

PHP Code:
if( xs_vec_equal(vecDir1vecDir2) ) 
About ...distance between 2 lines, so you have to get 2 vectors and get the difference. The result will be a vector (vector - vector = vector)...

This subtraction only finds a relationship between lines.

Real distance are calculate like I did in my example. Also it return a number, you must proportionate the correct unit type.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 10-01-2012 at 17:52.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 10-01-2012 , 19:03   Re: Distance between two lines
Reply With Quote #10

Quote:
Originally Posted by gladius View Post
Two lines are parallel if their direction vectors are equal.

PHP Code:
if( xs_vec_equal(vecDir1vecDir2) ) 
About ...distance between 2 lines, so you have to get 2 vectors and get the difference. The result will be a vector (vector - vector = vector)...

This subtraction only finds a relationship between lines.

Real distance are calculate like I did in my example. Also it return a number, you must proportionate the correct unit type.
Sure, you can get a distance from 2 points, or at least a minimum distance from a point and a line.
What happens if both lines are not parallel? Somewhere they will be closer and somewhere not.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
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 06:53.


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