Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Find a point on a line that is a certain distance along the line

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Nov 2020 02:44
Right now i have it working with GetWorldX/YFromSprite() but it would be nice to have an algorithm.
I did find something at stack overflow but it is way over the top and i'm pretty sure it's simple math but i'm stoopid
Thanks in advance for any help

Attachments

Login to view attachments
Lupo4mica37
4
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 1st Nov 2020 03:05
That reminds me of when you helped me with the function for placing a point along a line. I got the calculations for how to place the point along a line, not sure what you mean by find a point along a line? In what way to find? mouse pointer x/y input?
????????
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Nov 2020 03:37
I have point1, point2 and a distance
I need the point that is distance from point1 on the line
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Nov 2020 04:27 Edited at: 1st Nov 2020 04:28
Quote: "Right now i have it working with GetWorldX/YFromSprite() ... I need the point that is distance from point1 on the line"


not sure what i'm missing because i think you're already doing similar:

??
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Nov 2020 05:39
That's what i need VN. Thanks matey
smerf
19
Years of Service
User Offline
Joined: 24th Feb 2005
Location: nm usa
Posted: 1st Nov 2020 17:32 Edited at: 1st Nov 2020 17:47
function get_distance3d(x1#,y1#,z1#,x2#,y2#,z2#)
adjecent#=sqrt((x2#-x1#)*(x2#-x1#) + (y2#-y1#)*(y2#-y1#)) + (z2#-z1#)*(z2#-z1#)) //2d distance adjecent
endfunction adjecent#


you can find the hpotenuse /distance by the adjecent and opposite or vise versa using basic triangle math an a couple equations. Triangles are good for lots of stuff and knowing some triangle math u can accurately plot an orbit find distances, pivots, slopes, can even do real time shadows using a triangle crawler. Very valuable to take an hour and freshen up on some trig.

Lupo4mica37
4
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 1st Nov 2020 22:33
Yep, here is a LINK for quiet a lot of formulas that you can use for whatever type of triangle.
????????
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Nov 2020 05:54 Edited at: 4th Nov 2020 05:55
Given a line segment of point A[x1, y2] to point B[x2, y2]


1. Find length of the line segment:
length = sqrt((x1-x2)^2 + (y1-y2)^2)

2. Create normalized direction vector (or unit vector):
dx = (x2 - x1) / length
dy = (y2 - y1) / length


3. Find new point along line at specified distance:
x = x1 + dx * distance
y = y1 + dy * distance



I have a solution in DBP (somewhere) for distance along a bezier curve. It's harder than you'd think.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 4th Nov 2020 07:07
Wow! A wealth of knowledge. Thanks everyone
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 4th Nov 2020 13:05

if you have an AtanFull or a GetAngle function.

It's just matter of

Angle# = GetAngle(P1X,p1Y, P2X,P2Y)

X#= P1X+Cos(Angle#) *Distance#
Y#= P1Y+Sin(Angle#) *Distance#


PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Lupo4mica37
4
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 4th Nov 2020 22:13
@Phaelax Thank you master! Can you please find the calculations you have to find distance along a bezier curve PLEASE and share it here. Would be much appreciated. Thank you!
????????
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Nov 2020 01:41
Lupo4mica37
4
Years of Service
User Offline
Joined: 1st Jun 2020
Location:
Posted: 5th Nov 2020 02:10
Thank you blink0k!
????????

Login to post a reply

Server time is: 2024-11-21 22:36:15
Your offset time is: 2024-11-21 22:36:15