[QUESTION] How to get point to point distance?

Started by TheMallard, Feb 13, 2016, 01:04 PM

Previous topic - Next topic

TheMallard

Hello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}

KAKAN

#1
Nope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

 :edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
  v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
  return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
  /*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
  */
}
I haven't made it, @Cutton did.
oh no

TheMallard

My function works properly.

Class Vector has a method, called "Length()"

.

#3
Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

He's not talking about the container element count /length such as array/table/string. He's talking about the the distance between two points in 3 dimensional space. And the method he's calling is on the Vector instance.
.

ysc3839

Quote from: KAKAN on Feb 13, 2016, 01:06 PMNope. You can't get the length of a class/instance.

And the length function is: len() and not Length()
Still then, I can't know what you're talking about.

 :edit: This code might help you:-
function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
  v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
  return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
  /*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
  */
}
I haven't made it, @Cutton did.
You are wrong. Vector has the "Length" method.

FarisDon

Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found over here, than why make functions, I'm just curious to know why?

ysc3839

Quote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PM
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.

FarisDon

Quote from: ysc3839 on Feb 13, 2016, 08:39 PM
Quote from: [TBS]Destroyer on Feb 13, 2016, 07:29 PM
Quote from: TheMallard on Feb 13, 2016, 01:04 PMHello!
I've created a small function, and I don't know, it works properly or not.
Is this the right code?
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}
Why did you actually create the code,
It could have been Found over here, than why make functions, I'm just curious to know why?
Maybe he don't know there is such function. I don't know too.
Okay, well that's not really a serious problem/issue thou.

Thijn

You can use Vector.Distance( Vector) to get the distance in 3d.
function getPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
 return Vector(x, y, z).Distance( Vector( x2, y2, z2 ) );
}