Raised This Month: $51 Target: $400
 12% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blinx
Senior Member
Join Date: Oct 2013
Old 07-14-2022 , 15:40   [Maths] Given 2 points, retrieve a point between them
Reply With Quote #1

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.



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.
Blinx is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-14-2022 , 15:43   Re: [Maths] Given 2 points, retrieve a point between them
Reply With Quote #2

Quote:
Originally Posted by Blinx View Post
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.



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
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Blinx
Senior Member
Join Date: Oct 2013
Old 07-14-2022 , 16:43   Re: [Maths] Given 2 points, retrieve a point between them
Reply With Quote #3

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!

Last edited by Blinx; 07-14-2022 at 19:19.
Blinx is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 07-14-2022 , 21:13   Re: [Maths] Given 2 points, retrieve a point between them
Reply With Quote #4

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.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-15-2022 , 10:15   Re: [Maths] Given 2 points, retrieve a point between them
Reply With Quote #5

Quote:
Originally Posted by Blinx View Post
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
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:06.


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