GetDistanceBetweenPoints3D: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
__NOTOC__
__NOTOC__
==Description==
This function returns the distance between two 3 dimensional points using the pythagorean theorem.
This function returns the distance between two 3 dimensional points using the pythagorean theorem.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">getDistanceBetweenPoints3D ( x1, y1, z1, x2, y2, z2 )</syntaxhighlight>
<syntaxhighlight lang="lua">float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
Line 13: Line 12:
* '''y2''': The Y position of the second point
* '''y2''': The Y position of the second point
* '''z2''': The Z position of the second point
* '''z2''': The Z position of the second point
===Returns===
Returns the distance between the two points as a [[float]]. Returns ''false'' if an argument passed was invalid.


==Example==
==Example==
<syntaxhighlight lang="lua">vehiclex, vehicley, vehiclez = getVehiclePosition ( vehicle )
This example gets the distance between two vehicles and outputs it to the chat box.
vehicle2x, vehicle2y, vehicle2z = getVehiclePosition ( vehicle2 )
<syntaxhighlight lang="lua">vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle )
outputChatBox ( "The distance between vehicle and vehicle2 is ", getDistanceBetweenPoints3D ( vehiclex, vehicley, vehiclez, vehicle2x, vehicle2y, vehicle2z ) )</syntaxhighlight>
vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 )
outputChatBox ( "The distance between vehicle1 and vehicle2 is ", getDistanceBetweenPoints3D ( vehicle1x, vehicle1y, vehicle1z, vehicle2x, vehicle2y, vehicle2z ) )</syntaxhighlight>


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Revision as of 14:28, 14 August 2006

This function returns the distance between two 3 dimensional points using the pythagorean theorem.

Syntax

float getDistanceBetweenPoints3D ( float x1, float y1, float z1, float x2, float y2, float z2 )

Required Arguments

  • x1: The X position of the first point
  • y1: The Y position of the first point
  • z1: The Z position of the first point
  • x2: The X position of the second point
  • y2: The Y position of the second point
  • z2: The Z position of the second point

Returns

Returns the distance between the two points as a float. Returns false if an argument passed was invalid.

Example

This example gets the distance between two vehicles and outputs it to the chat box.

vehicle1x, vehicle1y, vehicle1z = getElementPosition ( vehicle )
vehicle2x, vehicle2y, vehicle2z = getElementPosition ( vehicle2 )
outputChatBox ( "The distance between vehicle1 and vehicle2 is ", getDistanceBetweenPoints3D ( vehicle1x, vehicle1y, vehicle1z, vehicle2x, vehicle2y, vehicle2z ) )

See Also