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

Calculating distance between aiming line and entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lazarev
Veteran Member
Join Date: Sep 2008
Old 08-01-2011 , 11:13   Calculating distance between aiming line and entity
Reply With Quote #1

Here's an example:
[img]http://img708.**************/img708/8715/requestc.jpg[/img]


red square is some entity, blue is me, aiming is aiming line, distance is the distance I want to get
lazarev is offline
Ryokin
Senior Member
Join Date: Jan 2010
Old 08-01-2011 , 11:20   Re: Calculating distance between aiming line and entity
Reply With Quote #2

PHP Code:
stock get_distance_to_line(Float:pos_start[3], Float:pos_end[3], Float:pos_object[3])  
{  
    new 
Float:vec_start_end[3], Float:vec_start_object[3], Float:vec_end_object[3], Float:vec_end_start[3]
    
xs_vec_sub(pos_endpos_startvec_start_end)         // vector from start to end 
    
xs_vec_sub(pos_objectpos_startvec_start_object)     // vector from end to object 
    
xs_vec_sub(pos_startpos_endvec_end_start)         // vector from end to start 
    
xs_vec_sub(pos_endpos_objectvec_end_object)         // vector object to end 
    
    
new Float:len_start_object getVecLen(vec_start_object
    new 
Float:angle_start floatacos(xs_vec_dot(vec_start_endvec_start_object) / (getVecLen(vec_start_end) * len_start_object), degrees)  
    new 
Float:angle_end floatacos(xs_vec_dot(vec_end_startvec_end_object) / (getVecLen(vec_end_start) * getVecLen(vec_end_object)), degrees)  

    if(
angle_start <= 90.0 && angle_end <= 90.0
        return 
floatround(len_start_object floatsin(angle_startdegrees)) 
    return -
1  

__________________
NH4CL + NaOH -> NH3 + H2O + NaCL
Ryokin is offline
Old 08-01-2011, 11:49
lazarev
This message has been deleted by lazarev. Reason: I was wrong.
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-01-2011 , 12:32   Re: Calculating distance between aiming line and entity
Reply With Quote #3

Note that the stock will get the line perpendicular to your aim vector for the smallest distance to your aim vector.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 08-01-2011 , 13:25   Re: Calculating distance between aiming line and entity
Reply With Quote #4

Quote:
Originally Posted by Exolent[jNr] View Post
Note that the stock will get the line perpendicular to your aim vector for the smallest distance to your aim vector.
Well, distance from point to line, is the perpendicular to the line drawn from the point.
SpeeDeeR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-01-2011 , 13:34   Re: Calculating distance between aiming line and entity
Reply With Quote #5

Quote:
Originally Posted by SpeeDeeR View Post
Well, distance from point to line, is the perpendicular to the line drawn from the point.
Yes, I know. I was only stating it since his picture does not show that.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 04:39.


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