r/desmos • • 4d ago

Question: Solved Function to find intersection?

Post image

How can I find the intersection point(s) between 2 parametric functions?

15 Upvotes

7 comments sorted by

16

u/Danny_DeWario https://www.desmos.com/calculator/75jcsa2dxv 4d ago

In general, you can create a system of 2 equations and solve for the 2 different 't' variables. In Desmos, this can be done automatically with regressions: https://www.desmos.com/calculator/7yzzkrhjgq

5

u/J053_r3dd1t 4d ago

Wow, this Is the Best and easiest explanation, thanks!

5

u/Danny_DeWario https://www.desmos.com/calculator/75jcsa2dxv 4d ago • Bravo

No problem!

An extra tip, regressions in Desmos don't have any built-in controls for what range to search for a solution. This can be a problem for when your equations have multiple solutions (multiple intersections).

Luckily, there's a workaround. You can set the upper/lower bounds for your 't' variables like this: https://www.desmos.com/calculator/kdn9uyms6z

4

u/meutzitzu 4d ago

You can't easily find the intersection of 2 segments. You can easily find the intersection between 2 lines, and then you can work out whether that point lies within the paralelogram shaped locus of all points which project onto the "active" segment part of both lines

4

u/brandonyorkhessler 4d ago

this is in general not going to have a closed form solution. however, in your case, they form straight lines, so they do:

2

u/Electronic-Laugh-671 my first Reddit user flair 4d ago

If I have two parametric functions f(t) and g(t). Each of them outputs a point. So when they intersect, f(t).y = g(t).y, and f(t).x = g(t).x

Across both of those equivalencies, you perform an intersection calculation. Desmos doesn't have a built in solver function (as far as I know), so you have to code it yourself. Here is an example (change g(x) in the code to be something like j(t) = (g(t).x - f(t).x) + (g(t).y - f(t).y), and update the parts where g(t) is used) Technically, this is a root solver for j(t).

https://www.desmos.com/calculator/bh27edggap

This will give you the t-value of the intersection, which you can then plug into either f(t) or g(t)

Let me know if this doesn't work, I haven't tried using the code for parametrics before but that shoudl work in theory

edit: I completely forgot about regressions, the method DannyDeWario mentioned would probably be much easier and more accurate

1

u/ci139 4d ago

the o=o.x+o.y & p=p.x+p.y the line equations thus are

o.x+At=p.x+Bs // note that the t and s are independent variable parameters
o.y+Dt=p.y+Cs // since all other data but s & t are defined and/or fixed you need to solve for s & t

goes like :

At–Bs=F=Const.1=p.x–o.x
Dt–Cs=E=Const.2=p.y–o.y

t–(B/A)s=F/A if A≠0
t–(C/D)s=E/D if D≠0
s=(F/A–E/D)/(C/D–B/A)=(FD–EA)/(CA–BD)

similarly

(A/B)t–s=F/B if B≠0
(D/C)t–s=E/C if C≠0
t=(F/B–E/C)/(A/B–D/C)=(FC–EB)/(AC–DB)

since the denominators are equivalent we can use G=AC–DB
s=(FD–EA)/G & t=(FC–EB)/G

t is related to point o and s is related to point p

the intersection if exists is at
o+t(cos α,sinα) --or-- p+s(cos β,sin β)

since there could be some arithmetic error you can average the 2 to be more precise in average

https://www.desmos.com/calculator/np0ksopnfi -- the p.j3 is interception found by non-parametric line parameters (is included in averaging)