AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [Maths] Given 2 points, retrieve a point between them (https://forums.alliedmods.net/showthread.php?t=338592)

Blinx 07-14-2022 15:40

[Maths] Given 2 points, retrieve a point between them
 
Hey there, I'm having trouble with a maths problem that I don't know how to put into code, hopefully this diagram helps explain what I'm looking for.

https://i.imgur.com/5q3byW7.png

I have 2 points, Point A and Point B, I want to travel along the line between them for a set amount of distance and then retrieve Point C. I can get the angle of this line no problem, I just don't know how to travel a set distance along it. It'd be like a TraceRay except you use a vector and travel along it a fixed distance and retrieve the end point.

Thanks for your time.

eyal282 07-14-2022 15:43

Re: [Maths] Given 2 points, retrieve a point between them
 
Quote:

Originally Posted by Blinx (Post 2783775)
Hey there, I'm having trouble with a maths problem that I don't know how to put into code, hopefully this diagram helps explain what I'm looking for.

https://i.imgur.com/5q3byW7.png

I have 2 points, Point A and Point B, I want to travel along the line between them for a set amount of distance and then retrieve Point C. I can get the angle of this line no problem, I just don't know how to travel a set distance along it. It'd be like a TraceRay except you use a vector and travel along it a fixed distance and retrieve the end point.

Thanks for your time.

I don't understand about this topic at all, but through sheer copy paste power my Useful Commands plugin does something almost identical:

Teleports you to a target position on where I aim, and if you're stuck, teleports you backwards across the angle of my aim until you're not stuck

https://github.com/eyal282/Useful-Co...fulCommands.sp

sm_blink

Blinx 07-14-2022 16:43

Re: [Maths] Given 2 points, retrieve a point between them
 
Hey there, thanks for the pointer, I've made a solution from it that works reasonably well, it only slightly falls short because the distance is a scalevector created from angles, so the distance is fairly inconsistent, but it generally works. Thanks.

Edit: Actually, with normalizing the vector and scaling it by a greater amount it gives a much more consistent result, cheers!

nosoop 07-14-2022 21:13

Re: [Maths] Given 2 points, retrieve a point between them
 
If you have the two points A and B and need a distance L along the line from the start, you'd want to create a vector from B - A, then normalize and scale by L.

If you have one point A and an angle, get the forward unit vector from the angle (in SourceMod you'd use GetAngleVectors), then scale that by L.

eyal282 07-15-2022 10:15

Re: [Maths] Given 2 points, retrieve a point between them
 
Quote:

Originally Posted by Blinx (Post 2783779)
Hey there, thanks for the pointer, I've made a solution from it that works reasonably well, it only slightly falls short because the distance is a scalevector created from angles, so the distance is fairly inconsistent, but it generally works. Thanks.

Edit: Actually, with normalizing the vector and scaling it by a greater amount it gives a much more consistent result, cheers!

Nice, but as promised I have no clue what you said :D


All times are GMT -4. The time now is 21:02.

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