finding the nearest point on the segment

Status
Not open for further replies.

xAmUser

Active member
Joined
Feb 23, 2018
Messages
55
Reaction score
2
Hello, please tell me how to find the nearest point on the segment A B from point C in three measuring space?
 

Attachments

  • Безымянный.png
    Безымянный.png
    3.5 KB · Views: 48

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
Hello, please tell me how to find the nearest point on the segment A B from point C in three measuring space?

If I relied on a hunch of mine, you're trying to find the shortest travel path, but what kind of travel do you intend to do? Will it be an:
  1. Adjacent Travel
    • PointC -> PointD -> Point A
    • PointC -> PointD -> Point B
  2. Straight Path Travel
    • PointC -> Point A
    • PointC -> Point B

But if I'll pick my Guess, here is an example body to find the shortest path when doing an adjacent travel.
PHP:
... // some certain part of a script

const
    Node_Distance = 31@
    Nearest_Distance = 30@
    Nearest_CoordX = 28@
    Nearest_CoordY = 27@
    Nearest_CoordZ = 26@
       // Point C
    Base_CoordX = 0@
    Base_CoordY = 1@
    Base_CoordZ = 2@
      //
      // Compared Point (A and B)
    Compared_CoordX = 3@
    Compared_CoordY = 4@
    Compared_CoordZ = 5@
end

    // Initialize
Nearest_Distance = 99999.0
Nearest_CoordX = 0xFFFFFFFF // NaN
Nearest_CoordY = 0xFFFFFFFF // NaN
Nearest_CoordZ = 0xFFFFFFFF // NaN
    //

    // put Coordinates of Point C to Base_Coord
00A0: store_actor $PLAYER_ACTOR position_to Base_CoordX Base_CoordY Base_CoordZ // example Point C

    // put Coordinates of Point D to Compared_Coord
Compared_CoordX = 382.3
Compared_CoordY = 2283.5
Compared_CoordZ = 4.5
050A: Node_Distance = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ
and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between C and D
    // starting now, the base coordinate separating the two possible paths is Point D
0087: Base_CoordX = Compared_CoordX
0087: Base_CoordY = Compared_CoordY
0087: Base_CoordZ = Compared_CoordZ

    // put Coordinates of Point A to Compared_Coord
00A0: store_actor 6@ position_to Compared_CoordX Compared_CoordY Compared_CoordZ // example Point A
050A: 7@ = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between Point D and Point A
005B: 7@ += Node_Distance // travel distance From PointC To PointD To PointA
if 0025: Nearest_Distance > 7@ // Point A is nearer than any other points
then // save the coordinates
    0087: Nearest_Distance = 7@
    0087: Nearest_CoordX = Compared_CoordX
    0087: Nearest_CoordY = Compared_CoordY
    0087: Nearest_CoordZ = Compared_CoordZ
end

    // put Coordinates of Point B to Compared_Coord
Compared_CoordX = 382.3
Compared_CoordY = 2283.5
Compared_CoordZ = 4.5
050A: 7@ = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ
and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between Point D and Poiny B
005B: 7@ += Node_Distance // travel distance From PointC To PointD To PointB
if 0025: Nearest_Distance > 7@ // Point B is nearer than any other points
then // save the coordinates
    0087: Nearest_Distance = 7@
    0087: Nearest_CoordX = Compared_CoordX
    0087: Nearest_CoordY = Compared_CoordY
    0087: Nearest_CoordZ = Compared_CoordZ
end
    // Point with the shortest path is now stored at Nearest_Coord
... //  certain part of the script
 

xAmUser

Active member
Joined
Feb 23, 2018
Messages
55
Reaction score
2

  1. Adjacent Travel
    • PointC -> PointD -> Point A
    • PointC -> PointD -> Point B
  2. Straight Path Travel
    • PointC -> Point A
    • PointC -> Point B

But if I'll pick my Guess, here is an example body to find the shortest path when doing an adjacent travel.
PHP:
... // some certain part of a script

const
    Node_Distance = 31@
    Nearest_Distance = 30@
    Nearest_CoordX = 28@
    Nearest_CoordY = 27@
    Nearest_CoordZ = 26@
       // Point C
    Base_CoordX = 0@
    Base_CoordY = 1@
    Base_CoordZ = 2@
      //
      // Compared Point (A and B)
    Compared_CoordX = 3@
    Compared_CoordY = 4@
    Compared_CoordZ = 5@
end

    // Initialize
Nearest_Distance = 99999.0
Nearest_CoordX = 0xFFFFFFFF // NaN
Nearest_CoordY = 0xFFFFFFFF // NaN
Nearest_CoordZ = 0xFFFFFFFF // NaN
    //

    // put Coordinates of Point C to Base_Coord
00A0: store_actor $PLAYER_ACTOR position_to Base_CoordX Base_CoordY Base_CoordZ // example Point C

    // put Coordinates of Point D to Compared_Coord
Compared_CoordX = 382.3
Compared_CoordY = 2283.5
Compared_CoordZ = 4.5
050A: Node_Distance = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ
and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between C and D
    // starting now, the base coordinate separating the two possible paths is Point D
0087: Base_CoordX = Compared_CoordX
0087: Base_CoordY = Compared_CoordY
0087: Base_CoordZ = Compared_CoordZ

    // put Coordinates of Point A to Compared_Coord
00A0: store_actor 6@ position_to Compared_CoordX Compared_CoordY Compared_CoordZ // example Point A
050A: 7@ = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between Point D and Point A
005B: 7@ += Node_Distance // travel distance From PointC To PointD To PointA
if 0025: Nearest_Distance > 7@ // Point A is nearer than any other points
then // save the coordinates
    0087: Nearest_Distance = 7@
    0087: Nearest_CoordX = Compared_CoordX
    0087: Nearest_CoordY = Compared_CoordY
    0087: Nearest_CoordZ = Compared_CoordZ
end

    // put Coordinates of Point B to Compared_Coord
Compared_CoordX = 382.3
Compared_CoordY = 2283.5
Compared_CoordZ = 4.5
050A: 7@ = distance_between_XYZ Base_CoordX Base_CoordY Base_CoordZ
and_XYZ Compared_CoordX Compared_CoordY Compared_CoordZ // get distance between Point D and Poiny B
005B: 7@ += Node_Distance // travel distance From PointC To PointD To PointB
if 0025: Nearest_Distance > 7@ // Point B is nearer than any other points
then // save the coordinates
    0087: Nearest_Distance = 7@
    0087: Nearest_CoordX = Compared_CoordX
    0087: Nearest_CoordY = Compared_CoordY
    0087: Nearest_CoordZ = Compared_CoordZ
end
    // Point with the shortest path is now stored at Nearest_Coord
... //  certain part of the script
how to make Compare Point (A and B)?
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
Do you mean this is?
PHP:
const
    Node_Distance = 31@
    Nearest_Distance = 30@
    Nearest_CoordX = 28@
    Nearest_CoordY = 27@
    Nearest_CoordZ = 26@
       // Point C
    Base_CoordX = 0@
    Base_CoordY = 1@
    Base_CoordZ = 2@
      //
      // Compared Point (A and B)
    Compared_CoordX = 3@
    Compared_CoordY = 4@
    Compared_CoordZ = 5@
end
These are just Variable Referencing, more like an alias from one to another. This part:
PHP:
Const
    Compared_CoordX = 3@
End
Tells the script that Compared_CoordX is a name of variable 3@. I only do this so that the readability of the script is understandable. If the comment at the constant naming part confuses you, ignore it and proceed on analyzing how the script idea works below it.
 

xAmUser

Active member
Joined
Feb 23, 2018
Messages
55
Reaction score
2
Do you mean this is?

These are just Variable Referencing, more like an alias from one to another. This part:
PHP:
Const
    Compared_CoordX = 3@
End
Tells the script that Compared_CoordX is a name of variable 3@. I only do this so that the readability of the script is understandable. If the comment at the constant naming part confuses you, ignore it and proceed on analyzing how the script idea works below it.
here is the calculation of points a and c. I need to calculate the closest distance from the point C to the segment A B
 
Status
Not open for further replies.
Top