Raised This Month: $ Target: $400
 0% 

Coordinates of a point related to two other points


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-19-2009 , 06:02   Coordinates of a point related to two other points
Reply With Quote #1

I would like to know if someone knows a way of getting the coordinates of a point that belongs to a line perpendicular to another one that connects two points. The last two points are known, and one of them is in the first line. Example:

[IMG]http://img19.**************/img19/2782/axis.jpg[/IMG]

Let's say that we are in the point A aiming at B. I want to have C knowing:

that the line AC is perpendicular to AB.
the length of AC.
the coordinates of A
the coordinates of B

I partially found a solution with some mathematical equations but, I have problems when the divisors get close to 0.

Ignore the Z-axis and be aware that the coordinates of each point differ from the other's, both in X-axis and Y-axis.
__________________

Last edited by joaquimandrade; 03-19-2009 at 12:40.
joaquimandrade is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 03-19-2009 , 10:06   Re: Coordinates of a point related to two other points
Reply With Quote #2

After you get C, you can use get_distance(_f) with the A and C coordinates.

PHP Code:
// d = square_root((a x a) + (b x b))
new Float:distance floatsqroot(((coordA[0] - coordC[0]) * (coordA[0] - coordC[0])) + ((coordA[1] - coordC[1]) * (coordA[1] - coordC[1]))); 
I'm pretty sure this is how get_distance works(except that it has Z also).
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ

Last edited by Dores; 03-19-2009 at 10:10.
Dores is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 03-19-2009 , 10:28   Re: Coordinates of a point related to two other points
Reply With Quote #3

@Dores

The length AC is one of the knowns. ;)

@joaquimandrade

Something like this should do:

Code:
public whatev(id) {     new Float:fLength = -100.0         new Float:fAngles[3], Float:fVector[3]         // get the direction the player is looking     pev( id, pev_v_angle, fAngles)         // get the vector perpendicular to his view     angle_vector( fAngles, ANGLEVECTOR_RIGHT, fVector )         // ignore z axis     fVector[2] = 0.0         // make vector one unit in length     xs_vec_normalize( fVector, fVector )         // increase length of vector in the negative direction, negative = left     xs_vec_mul_scalar( fVector, fLength, fVector ) }
__________________
stupok is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-19-2009 , 12:37   Re: Coordinates of a point related to two other points
Reply With Quote #4

Quote:
Originally Posted by stupok View Post
@Dores

The length AC is one of the knowns. ;)

@joaquimandrade

Something like this should do:
Thank you. It works.
__________________
joaquimandrade is offline
Dores
Veteran Member
Join Date: Jun 2008
Location: You really don't wanna k
Old 03-19-2009 , 13:55   Re: Coordinates of a point related to two other points
Reply With Quote #5

Quote:
Originally Posted by stupok View Post
@Dores

The length AC is one of the knowns. ;)
I must improve my English.
__________________
O o
/Ż________________________
| IMMA FIRIN' MAH LAZOR!!!
\_ŻŻŻ
Dores is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-19-2009 , 14:04   Re: Coordinates of a point related to two other points
Reply With Quote #6

Quote:
Originally Posted by Dores View Post
I must improve my English.
sorry i forgot to thank you too. At least you tried to help
__________________
joaquimandrade is offline
Reply


Thread Tools
Display Modes

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 08:49.


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