Segment intersection formula explained

Поделиться
HTML-код
  • Опубликовано: 22 окт 2024

Комментарии • 180

  • @cesarmoltoni
    @cesarmoltoni 10 месяцев назад +9

    Amazing tutorial Dr Radu, I have made a little change breaking "getIntersection" into two functions and interchanging arguments:
    function getIntersection(A, B, C, D) {
    const t = calculateOffsets(A, B, C, D)
    const u = calculateOffsets(C, D, A, B)
    if (t && u) {
    return {
    x: lerp(A.x, B.x, t),
    y: lerp(A.y, B.y, t),
    offset: t
    }
    }
    return null
    }
    function calculateOffsets(A, B, C, D) {
    const top = (D.y - C.y) * (A.x - C.x) - (D.x - C.x) * (A.y - C.y)
    const bottom = (D.x - C.x) * (B.y - A.y) - (D.y - C.y) * (B.x - A.x)
    if (bottom != 0.0) {
    const offset = top / bottom
    if (offset >= 0 && offset

    • @Radu
      @Radu  10 месяцев назад +2

      Hey! That's really nice :-)
      Pinning your comment for others to see!

    • @quentinquadrat9389
      @quentinquadrat9389 9 месяцев назад +1

      I found a bad case: AB = ((0.0f, 0.0f), (10.0f, 0.0f)) and CD = ((10.0f, 0.0f), (20.0f, 0.0f)) bottom will be 0 so it will find no solution while the intersection is 10.

    • @Radu
      @Radu  9 месяцев назад

      You're right! Bottom is also zero when points of the segments are collinear...
      I wonder what we can do about it? 🤔

    • @quentinquadrat9389
      @quentinquadrat9389 9 месяцев назад +1

      ​@@Radu better to keep talking on the ticket that I reopened on your virtual-world project. Tonight I'm busy. Yes collinearity is painful and shall be managed separately: if segment are superposed, you have plenty of intersections (but let say the 2 corners of the smaller segment), else 0 intersection when they are parallel, else 1 intersection. On other point in your road generation, you discard the case where segments are connected by a single vertex :)

    • @Radu
      @Radu  8 месяцев назад +1

      I will have to check those tickets at some point. Have had many things keeping me busy, recently :-\

  • @yandra_dev
    @yandra_dev 2 года назад +32

    I simply can't explain how much I love this guy, one of the best teachers I ever had.

  • @crypticmeow
    @crypticmeow Год назад +3

    One of the best tutor for learning maths and coding.

    • @Radu
      @Radu  Год назад

      Thank you :-)

  • @redundantqwail9088
    @redundantqwail9088 Год назад +2

    After trying a number of methods, I'd determined line segment collision detection to be an integral part of an effective way to determine A) if a sprites projected path is going to be intersecting a block B) which side of the block and therefore how to respond to it. I've looked at a number of resources that give similar equations with little explanation of beyond what the components are. I hate using math I don't understand in my projects, so the in depth explanation given here was a godsend. Keep producing awesome content!

    • @Radu
      @Radu  Год назад

      I'm happy to hear you found good uses for it :-) Thanks for watching!

  • @williamikennanwosu
    @williamikennanwosu 2 года назад +7

    You lay things out clearly, explain things well and code at a pace that is easy to follow along. Top notch teaching Radu 💯!

    • @Radu
      @Radu  2 года назад +1

      Thank you :-)

    • @williamikennanwosu
      @williamikennanwosu 2 года назад +1

      @@Radu You are very welcome Radu 😁!

  • @awekeningbro1207
    @awekeningbro1207 2 года назад +6

    i really love this sort of coding, which involves maths! It makes the problem so much more engaging and challenging!

    • @Radu
      @Radu  2 года назад +1

      I like it too... It also makes the math easier to understand when visualized like that. Thanks for watching!

  • @eugeniogonzato
    @eugeniogonzato 6 месяцев назад +1

    You opened my mind in a way that nobody did before, thanks.

    • @Radu
      @Radu  6 месяцев назад

      Happy to hear that :-)

  • @lukasaudir8
    @lukasaudir8 11 месяцев назад +1

    Radu is a super teacher!!
    Teaching the intuition and logic behind more complex topics, by simply breaking down the complex into smaller simple pieces is a brilliant way to teach, and surely the lesson will stick with the student forever,
    I'm glad that people like you exist and are willing to share that knowledge,
    Thank you Radu!!

    • @Radu
      @Radu  11 месяцев назад

      Glad to be of help :-)

  • @Eternam
    @Eternam 2 года назад +10

    a master class, thank you very much Radu, waiting for the next one.

    • @Radu
      @Radu  2 года назад +2

      Thanks Eternam :-) glad to hear you're excited!

  • @amitlavian
    @amitlavian 2 года назад +5

    Great stuff :) I really like the approach of visualizing things to make the explanations clearer

    • @Radu
      @Radu  2 года назад

      Thanks! I'll make try to make more things like this.

  • @LBCreateSpace
    @LBCreateSpace 4 месяца назад +1

    I love Radu. Great teacher.

    • @Radu
      @Radu  4 месяца назад

      Thanks :-)

  • @___d3p1
    @___d3p1 Год назад +1

    Great linear interpolation related video! I hope my English level could be good enough to be able to express gratitude for your videos. The creative way in which you explain, the program you develop to exemplify what is being explained in an entertaining way, the editing... all the time spent in front of the camera and off it, has great value to me. All your students should be proud to have such a great teacher!

    • @Radu
      @Radu  Год назад +1

      Thanks for the nice words, and thanks for watching :-)

  • @nurbekss2729
    @nurbekss2729 2 года назад +1

    Dude ,you have to become a prof.You are such genious of explaining the complex things in the easiest way.Thank you sir.

    • @Radu
      @Radu  2 года назад +1

      I got my PhD in 2017. Does it count? :-)

    • @nurbekss2729
      @nurbekss2729 2 года назад +1

      @@Radu Actually,I saw your PhD defending .I have to admit you did a great work!
      I just wanted to tell you about your pure talent of explanation.
      Always thought that I am dumb in math and will never get it.But after some "switches" to good written work or people who helped me to understand more clearly the subject ,I feel myself more confident in math right now .
      You know about people psychology/attitude .If you dont get once you will never return to it again ,saying it's not for me or it's too hard.So the world needs a good teachers and it doesn't matter if you are a prof in univ or youtube maker.
      Anyway love your content,wish you the best.
      P.s :Can't imagine my self studying CS w/o Stackoverflow or youtubers lol.

    • @Radu
      @Radu  Год назад

      Thanks for the nice comment :-) [PS: RUclips just enabled a feature that I can easily find these replies... wasn't possible until now]

  • @antonioguilherme1844
    @antonioguilherme1844 Год назад +1

    thank you teacher. I'm Brazilian, I was looking for some content about collision between line segments, but I couldn't find it, you saved me.

    • @Radu
      @Radu  Год назад

      Glad you found it useful. Another, more mathematical approach is linked in my video description.

  • @daiyaanmuhammad
    @daiyaanmuhammad 2 года назад +1

    Wow! Didn't even realize I actually watched a half hour content without skipping anything. Awesome explainations man. You've earned a sub.

    • @Radu
      @Radu  2 года назад

      Glad to hear :-) hope you'll find it useful!

  • @AtticusColdfield
    @AtticusColdfield 6 месяцев назад +1

    Okay. Well, THAT was INCREDIBLE!

    • @Radu
      @Radu  6 месяцев назад

      Haha, glad to hear :-)

  • @ScriptRaccoon
    @ScriptRaccoon 2 года назад +7

    This is a really good and pictorial explanation! As a mathematician I would have explained it quite differently, but probably you are right that this scares people away :D

    • @Radu
      @Radu  2 года назад +4

      I'm glad to see a mathematician agreeing with me :-) I was actually waiting for the opposite :-D what I did here is not really standard... and not a formal proof, but I feel these things are needed as well. Visualizing things like that helped me a lot during my research: not only to verify new ideas, but also to see if there are bugs in the code.

    • @abdulnafay72
      @abdulnafay72 11 месяцев назад

      Hey mathematician please teach me.

  • @henrmota
    @henrmota Год назад +1

    Underrated channel.

    • @Radu
      @Radu  Год назад

      Thanks for watching :-)

  • @bawbak8800
    @bawbak8800 Год назад +1

    Thank you sir, I really appreciate that you explained it in a programming way and not in the math way. 🙏
    You have no idea how many videos I've watched to understand this topic, but because all of them explained it with the math language, I couldn't comprehend it at all and it just frustrated me

    • @Radu
      @Radu  Год назад

      I'm happy to hear :-) it's the reason I made it.

  • @josephsam2145
    @josephsam2145 6 месяцев назад +1

    Thank you very much for your tutorials.

    • @Radu
      @Radu  6 месяцев назад

      Glad you like them! :-)

  • @bloppai9462
    @bloppai9462 Год назад +1

    Brilliant explanation, thank you so much!

    • @Radu
      @Radu  Год назад

      Glad it was helpful!

  • @hri7566
    @hri7566 2 года назад +1

    literally the only explanation i can find for the hardest part of raycasting

    • @Radu
      @Radu  2 года назад +1

      Really? There must be others as well :-) it's a popular topic!

  • @Radu
    @Radu  2 года назад +16

    Can you think of a way to use segment intersection in your project? :-)

    • @basiccoder2166
      @basiccoder2166 2 года назад +2

      I've tried to use intersection in roundabout and confused the hell out of myself (⊙_⊙;)

    • @basiccoder2166
      @basiccoder2166 2 года назад +1

      other way i was thinking about intersection is sorting that happens in production factory where 2 similar or different product either intersect or separate out

    • @Radu
      @Radu  2 года назад

      @@basiccoder2166 Oh, wow. Did you di intersection between line and circle then? :-)

    • @Radu
      @Radu  2 года назад

      @@basiccoder2166 Yeah, that's the (intersection) concept from set theory :-)

    • @basiccoder2166
      @basiccoder2166 2 года назад +1

      @@Radu yes tried to😂

  • @unknown-bx8my
    @unknown-bx8my 2 года назад +1

    Very useful!
    Right now, i know how to use this function in all cases as i need after understanding it. Thank you.

    • @Radu
      @Radu  2 года назад +1

      You're welcome!

  • @ЛюдмилаБаїк-ъ9ь
    @ЛюдмилаБаїк-ъ9ь Год назад +1

    Watched, it is just all about algebra, solving system of equations, at last I found the practical use of those countless school exercises )

    • @Radu
      @Radu  Год назад

      Yeah, one hope I have with these videos is to make people see that the things they learn in school are not 'useless'.

  • @DanielJoseAutodesk
    @DanielJoseAutodesk Год назад +1

    I liked.😁👍 Simple and direct. Very good teaching. Demonstrating mastery over what you want to explain 👏👏👏👏. So you've gained another subscriber. 👍😁

    • @Radu
      @Radu  Год назад

      Thank you :-)

  • @pand0ras
    @pand0ras 5 месяцев назад +1

    interesting approach, i just used the 2point vector form, and shuffled them around to get the intersection point. It's maybe a little bit easier.
    like (y2-y1)/(x2-x1) * (x-x1) *y1. Shorter, less to calculate.

    • @Radu
      @Radu  5 месяцев назад

      Nice work :-)

  • @coachtroop
    @coachtroop 2 года назад +1

    As all of your videos have been so far - very entertaining and enlightening. I am excited to see the rest of this series 😀
    Thank you for putting the effort into these.

    • @Radu
      @Radu  2 года назад

      Great to hear that :-) Thanks for watching!

  • @andresgardiol8111
    @andresgardiol8111 2 года назад +1

    Great video! I learn a lot with your tutorials!

    • @Radu
      @Radu  2 года назад

      Thanks :-) Happy to hear that!

  • @eitanbegayev9290
    @eitanbegayev9290 8 месяцев назад +2

    please explain how to find the uTop, u cant calculate it, i always get (B - A) there instead of (A - B), please help

  • @serveshchaturvedi2034
    @serveshchaturvedi2034 Год назад +1

    Thank you, professor Gem! 💎❤

  • @od1367
    @od1367 2 года назад

    Thank you for this explination. This is pobably the best vidoes i have seen on youtube relating to CS!!!!!!!!!!!!!!!!❤

    • @Radu
      @Radu  2 года назад

      Glad to hear that. I tried to handle the concept well.

  • @engtari
    @engtari 2 года назад +2

    Beautiful stuff

    • @Radu
      @Radu  2 года назад

      Thanks!

  • @eitanbegayev9290
    @eitanbegayev9290 8 месяцев назад +1

    please explain me how to get the uTop, mt calculation desn't work

  • @aitorplaza2560
    @aitorplaza2560 2 года назад +2

    Amazing video, as always. One question: is the drawing of the car need to be done by us, or did I miss something?
    waiting for the next video

    • @fleckenfurz77
      @fleckenfurz77 2 года назад +1

      You mean looking for a little picture of a car, and then simply replace..
      ctx.rect(....)
      with..
      ctx.drawImage(img, sx,sy,sw,sh, dx,dy,dw,dh)
      ???
      i believe in you! you can do it! ;-)

    • @aitorplaza2560
      @aitorplaza2560 2 года назад +1

      @@fleckenfurz77 ok, thank you. i'll try.

    • @Radu
      @Radu  2 года назад +1

      Thanks! About the car, I did post one challenge on my community tab where the goal was to make a car, but I will eventually show you how to draw it and how to make them have random colors (it will be the final lecture).

    • @aitorplaza2560
      @aitorplaza2560 2 года назад +1

      @@Radu Thank you! I'll wait for that lesson. Meanwhile, I'm really curoius about the ML part, I'm wainting for it!.

    • @Radu
      @Radu  2 года назад +3

      @@aitorplaza2560 Glad to hear. I've put the most effort into the Neural Network lecture. Should be out on 15th of April (on my birthday :-D) if all goes according to plan.

  • @calebcadainoo
    @calebcadainoo Год назад +2

    I really love your tutorials 👏👏
    How do I detect a shape click on the canvas?
    Example if I have a circle or rectangle on the canvas at any point and I click on any of them how will I know if the user clicked a section of the rectangle or circle?

    • @Radu
      @Radu  Год назад

      You may want to look into the 'isPointInPath' method of the canvas context.

    • @abdulnafay72
      @abdulnafay72 Месяц назад

      May be you can check if your mouseX and MouseY is same as PointX PointY

    • @calebcadainoo
      @calebcadainoo Месяц назад

      @@Radu oh okay 🔥🔥

  • @imnotchinese6235
    @imnotchinese6235 2 года назад +1

    i love your intro

    • @Radu
      @Radu  2 года назад +1

      Thank you :-) there's also an extended version if curious ruclips.net/video/33YwKcVQ1vw/видео.html

  • @Alex_Aly
    @Alex_Aly 2 года назад +1

    Slove the system ecuation composed of both linear equations d1:ax+by+c=0 and d2:ax+by+c=0, and you get the intersection point , but first test the slope for paralel lines. at least that is what I've tried.

    • @Radu
      @Radu  2 года назад

      You can do that. Have to also consider vertical lines (slope is undefined then).

  • @vasylp.4007
    @vasylp.4007 Год назад +2

    Hello. Can I get the code source of this video?

    • @Radu
      @Radu  Год назад

      Sorry, haven't saved this one since it doesn't really do anything...

  • @igor2703
    @igor2703 2 года назад

    English is not my native language, but I can perfectly understand everything you say.
    You are amazing, I love your channel and I wish I knew sooner!

    • @Radu
      @Radu  2 года назад +1

      Hi, and welcome to the channel :-)

  • @mattoattacko
    @mattoattacko 2 года назад +2

    your intro is great :D

    • @Radu
      @Radu  2 года назад +1

      Haha, thanks! There's an extended version on my channel :-)

    • @mattoattacko
      @mattoattacko 2 года назад +1

      @@Radu I showed it to my gf, and now we will just randomly sing "coding with Radu.🎶Coding with Radu🎶"

    • @Radu
      @Radu  2 года назад +1

      @@mattoattacko Probably a one hit wonder :-))

    • @mattoattacko
      @mattoattacko 2 года назад

      @@Radu Would win Eurovision IMO😁

    • @Radu
      @Radu  2 года назад

      @@mattoattacko Hahaha :-)) next year maybe!

  • @experimentnameuntitled22
    @experimentnameuntitled22 Год назад +1

    for the calculation of uTop, why is there a A.x - B.x instead of B.x - A.x? I followed the same steps as the steps for getting t and can't seem to get this result

    • @Radu
      @Radu  Год назад +1

      A.x - B.x is same as - (B.x - A.x). Could it be that you have another minus (-) sign somewhere that cancels this one out?

    • @experimentnameuntitled22
      @experimentnameuntitled22 Год назад +1

      @@Radu Thanks for the reply. Yeah I figured it out. I checked and the subtraction in the divisor of my u equation is actually reversed. So I had to multiply both side by -1 and got the same answer.

    • @Radu
      @Radu  Год назад +1

      Great!

  • @paulbaxter7002
    @paulbaxter7002 Год назад

    Excellent. The only thing I would suggest is adding a link to the code.

    • @Radu
      @Radu  Год назад

      Yeah, unfortunately it got deleted somehow 🤣

  • @abhishekgourav6144
    @abhishekgourav6144 5 месяцев назад +1

    Need to follow him...

    • @Radu
      @Radu  5 месяцев назад

      :-)

  • @fereshtekasra5038
    @fereshtekasra5038 Месяц назад +1

    You are an angle ,,,🎉❤😊

    • @Radu
      @Radu  29 дней назад

      :-)

  • @JeanDAVID
    @JeanDAVID Год назад +1

    is there a github to get the source files ? thanks

    • @Radu
      @Radu  Год назад +1

      You can get the code for getIntersection from the self driving car repository: github.com/gniziemazity/Self-driving-car
      But the code of this whole demonstration is not online.

  • @soussousalahiddine5933
    @soussousalahiddine5933 2 года назад +2

    you are awesome

    • @Radu
      @Radu  2 года назад

      Thanks :-) and thanks for watching!

  • @basiccoder2166
    @basiccoder2166 2 года назад +1

    out of curiosity is the function lerp is same as y = mx+t ?

    • @Radu
      @Radu  2 года назад +1

      What you're writing here is the line equation. And lerp, as the name says: 'linear' interpolation is also a line, yes.
      But in lerp m is defined as a difference between two end values, say: t and w (with your naming convention).
      So y=(w-t)x+t.
      That's because lerp is supposed to give you values for y within the interval [t,w] with values for x in [0,1].
      You can also use x outside of the [0,1] range and then it's called extrapolation.

    • @basiccoder2166
      @basiccoder2166 2 года назад +1

      @@Radu Thanks

    • @Radu
      @Radu  2 года назад +1

      @@basiccoder2166 No problem!

  • @georgetheprogrammer
    @georgetheprogrammer 2 года назад +1

    Rock lee reference. 🔥🔥🔥🔥🔥🔥🔥🔥

    • @Radu
      @Radu  2 года назад

      :-) yeah, one of my favorite scenes in the whole series.

  • @canimeup
    @canimeup Год назад

    love it!

    • @Radu
      @Radu  Год назад

      Cool! Thanks :-)

  • @moussadotco
    @moussadotco Год назад +1

    Cyprien fait des maths. Love it.

    • @Radu
      @Radu  Год назад

      Who is Cyprien? :-)

    • @moussadotco
      @moussadotco Год назад +1

      @@Radu ruclips.net/video/b5Q1K7jzZN4/видео.html

    • @Radu
      @Radu  Год назад

      :-))

  • @osamaabozahra
    @osamaabozahra 2 года назад

    Thanks for the wonderful content, very much appreciated.
    I just have a question which is killing me, you didn't initialize the variable myCanvas and somehow it is working with you, hooow?😃

    • @Radu
      @Radu  2 года назад +2

      All IDs defined using HTML are by default global variables. I don't do this very often because its easy to overwrite those if not careful... I don't recommend that practice, but for something like this, where we're not really building anything real, it's ok.
      Good question! I think not many people know this!

    • @osamaabozahra
      @osamaabozahra 2 года назад +1

      @@Radu wow this is new to me, I have an experience for like 4 years now and this is the first time to know this.
      Thanks again for the explanation and for the content.

    • @Radu
      @Radu  2 года назад +1

      @@osamaabozahra Maybe better that way :-) it's not a good practice, I think. And, I'm sure that after 4 years you know many other things I don't!
      Keep it up and thanks for watching!

  • @eitanbegayev9290
    @eitanbegayev9290 8 месяцев назад +2

    pleaseeee help me understand how to get th uTop. i cant do it. i get the wrong answer all the time idkw

    • @Radu
      @Radu  8 месяцев назад

      Hard to help in the comments... just keep in mind that the result you get can be different as long as it is equivalent. Like -(B-A) is the same as (A-B), but a minus (-) must be there.

    • @eitanbegayev9290
      @eitanbegayev9290 8 месяцев назад +1

      @@Radu yes, that waz the problem, thank you radu.
      I'm so happy i found your channel😇

    • @Radu
      @Radu  8 месяцев назад

      @@eitanbegayev9290 thanks for watching!

  • @boonga585
    @boonga585 4 месяца назад +1

    28:00

  • @MikkelGissel
    @MikkelGissel 2 года назад +1

    How is it possible to select the canvas on the id without a query selector? What is this sorcery! And thanks for great videoes - don't hold the math =)

    • @Radu
      @Radu  2 года назад +1

      They are globals, by default, but I don't recommend doing this. They can easily get overwritten.

  • @adilsonbuset738
    @adilsonbuset738 11 месяцев назад +1

    Valeu!

    • @Radu
      @Radu  11 месяцев назад

      E de bine? :-D

    • @adilsonbuset738
      @adilsonbuset738 11 месяцев назад +1

      Yes, Master, this class was awesome!@@Radu

    • @Radu
      @Radu  11 месяцев назад

      Merci :-)

  • @boonga585
    @boonga585 4 месяца назад +1

    19:55

    • @Radu
      @Radu  4 месяца назад

      What about it?

  • @RajVenkatVijayakumar
    @RajVenkatVijayakumar 4 месяца назад +1

    bro has 654 missed calls from microsoft

    • @Radu
      @Radu  4 месяца назад +1

      I hope not :-/ I worked for them a while back and missed calls might mean I did something bad :-D

  • @_gunnnu_
    @_gunnnu_ 2 года назад +2

    is the dropping of hand weights in your intro supposed to be a resemblance to Rock Lee from Naruto?

    • @Radu
      @Radu  2 года назад +1

      :-))) yes...

  • @Aaackermann
    @Aaackermann Год назад +1

    Here I transcribed the code: (But I made some minor changes to fit my needs, but It works and you might find this helpfull)
    let canvas = document.getElementById("canvas")
    let ctx = canvas.getContext("2d")
    let angle=0;
    const A={x:200, y:150};
    const B={x:150, y:250};
    const C={x:50, y:100};
    const D={x:250, y:200};
    const mouse={x:0,y:0};
    document.onmousemove=(event)=>{
    mouse.x=event.x;
    mouse.y=event.y;
    }
    function lerp(A,B,s)
    {
    return A+(B-A)*s
    }
    let t=-1;
    let u = -1;
    function drawDot(point,label,isOutside)
    {
    ctx.beginPath()
    ctx.fillStyle=isOutside?"red":"white";
    ctx.arc(point.x,point.y,10,0,Math.PI*2);
    ctx.fill()
    ctx.stroke();
    ctx.fillStyle="black";
    ctx.textBaseline="middle";
    ctx.font="bold 14px Arial"
    ctx.textAlign="center"
    ctx.fillText(label,point.x,point.y);
    }
    function animate()
    {
    const radius=50;
    A.x=mouse.x+Math.cos(angle)*radius;
    A.y=mouse.y-Math.sin(angle)*radius;
    B.x=mouse.x-Math.cos(angle)*radius;
    B.y=mouse.y+Math.sin(angle)*radius;
    angle+=0.02;
    ctx.clearRect(0,0,canvas.width,canvas.height);
    ctx.beginPath();
    ctx.moveTo(A.x, A.y);
    ctx.lineTo(B.x, B.y)
    ctx.moveTo(C.x, C.y);
    ctx.lineTo(D.x, D.y)
    ctx.stroke();
    drawDot(A,"A",false);
    drawDot(B,"B",false);
    drawDot(C,"C",false);
    drawDot(D,"D",false);
    let M={
    x:lerp(A.x,B.x,t),
    y:lerp(A.y,B.y,t)
    }
    let N={
    x:lerp(C.x,D.x,u),
    y:lerp(C.y,D.y,u)
    }
    const I=getIntersection(A,B,C,D);
    if (I) {drawDot(I,"I",false)}
    //ctx.beginPath();
    //ctx.rect(canvas.width/2,0,I.bottom/100,10);
    //ctx.fill();
    drawDot(N,"N",u1);
    u+=0.005;
    drawDot(M,"M",t1);
    t+=0.005;
    requestAnimationFrame(animate);
    }
    function getIntersection(A,B,C,D){
    const vTop=(D.x-C.x)*(A.y-C.y)-(D.y-C.y)*(A.x-C.x);
    const uTop=(C.y-A.y)*(A.x-B.x)-(C.x-A.x)*(A.y-B.y);
    const bottom=(D.y-C.y)*(B.x-A.x)-(D.x-C.x)*(B.y-A.y);
    if(bottom!=0){
    const v=vTop/bottom;
    const u=uTop/bottom;
    if(v>=0 && v=0 && u

    • @Radu
      @Radu  Год назад

      Thanks!

  • @jubrazkhan255
    @jubrazkhan255 2 года назад +1

    How to select rectangle and resize rectangle please help me. I made drawing app

    • @Radu
      @Radu  2 года назад +1

      Can you share some sample code you're working with? I'm not sure I understand your problem...

  • @mazlumkoyuncu5549
    @mazlumkoyuncu5549 Год назад +1

    now i realize i was always using lerp to generate random number between min and max value😅

    • @Radu
      @Radu  Год назад

      Cool :-) you probably know lerp very well in that case... probably just didn't know it has a name.

  • @rmsv
    @rmsv Год назад +1

    If the two segments overlap, there are parallel but collision occurs.

    • @Radu
      @Radu  Год назад

      True, would you implement this differently?

    • @rmsv
      @rmsv Год назад +1

      @@Radu If the segments overlap, I would return a point of intersection anywhere in the region of overlap, maybe using both segments current direction of movement to set a collision point that's "happening first". What's your take on this? Was it intentional to not trigger a collision with overlapping segments?

    • @Radu
      @Radu  Год назад

      @@rmsv Well, if they overlap there is no collision 'point' but a collision 'segment'... so proper way would be to return that. Now, I couldn't possibly return all (infinitely many) points that form that segment :-) so maybe returning it as a kind of interval that represents all points within the range. I don't know :-| another possible way would be to return nothing... if intersection would mean that one segment must have one endpoint on one side and another on the other (which overlapping segments do not have). I think this is actually the case in this video. Would have to check the code again to verify and I'm not at the office, so I'll probably forget :-D

  • @abdulnafay72
    @abdulnafay72 11 месяцев назад +1

    Holy Shit 😂. Can you teach me mathematics?

    • @Radu
      @Radu  11 месяцев назад +1

      Probably, since you watched this video, I already did :-D

  • @Xoundz
    @Xoundz 2 года назад +1

    *How did you do that !???*
    😯😲😳🤯

    • @Radu
      @Radu  2 года назад

      Do what exactly? :-)

    • @Xoundz
      @Xoundz 2 года назад +1

      @@Radu
      I really love and admire your thinking and explaining capabilities. You are JUST amazing !
      I am continuously watching your videos from last 3 days and feel JS is easy and fun.
      Understanding mathematical expressions taking some time, though. 🤭

    • @Radu
      @Radu  2 года назад

      @@Xoundz Thank you :-) happy to hear you're learning!

  • @zVOLT220z
    @zVOLT220z Год назад +1

    My head is gonna explode

    • @Radu
      @Radu  Год назад

      You find it difficult? Which part is causing you trouble?

    • @zVOLT220z
      @zVOLT220z Год назад +1

      @@Radu The part of getting back to math, even tho it's basic math I'm not used to think at all, I did the uTop alone and got the same as you (glad for that). I do got questions for this project on C#, as I'm stuck in this part specificaly, whenever I try to create my lines, I put them in a Canvas but for some reason they all get messed up, the orientations isn't good and half of the lines get hidden for some unknown reason to me. It does work with Rectangles, except I don't know how to get their coordinates inside the Canvas. Thanks for the lessons, I watched everything twice now. I'm doing an Automation bachelor degree and A.I. is something I want to get to know, in it's raw state.

    • @Radu
      @Radu  Год назад

      @@zVOLT220z Glad to hear you find this useful. If you're having trouble with doing it in C# you could try sharing the code (like maybe on my Discord) and I'll have a look.

  • @__________________________6910
    @__________________________6910 2 года назад +2

    Coding with radu la la la

  • @exploring.the.world2023
    @exploring.the.world2023 2 года назад +2

    Fain

    • @Radu
      @Radu  2 года назад +1

      Merci :-)