AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Coordinates of a point related to two other points (https://forums.alliedmods.net/showthread.php?t=87996)

joaquimandrade 03-19-2009 06:02

Coordinates of a point related to two other points
 
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.

Dores 03-19-2009 10:06

Re: Coordinates of a point related to two other points
 
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).

stupok 03-19-2009 10:28

Re: Coordinates of a point related to two other points
 
@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 ) }

joaquimandrade 03-19-2009 12:37

Re: Coordinates of a point related to two other points
 
Quote:

Originally Posted by stupok (Post 784401)
@Dores

The length AC is one of the knowns. ;)

@joaquimandrade

Something like this should do:

Thank you. It works.

Dores 03-19-2009 13:55

Re: Coordinates of a point related to two other points
 
Quote:

Originally Posted by stupok (Post 784401)
@Dores

The length AC is one of the knowns. ;)

I must improve my English. :shock:

joaquimandrade 03-19-2009 14:04

Re: Coordinates of a point related to two other points
 
Quote:

Originally Posted by Dores (Post 784536)
I must improve my English. :shock:

:) sorry i forgot to thank you too. At least you tried to help


All times are GMT -4. The time now is 08:49.

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