A Virtual World - JavaScript Course: Lesson 4 / 11 [Polygon Operations in JavaScript]

Поділитися
Вставка
  • Опубліковано 15 лис 2024

КОМЕНТАРІ • 84

  • @quentinquadrat9389
    @quentinquadrat9389 9 місяців тому +3

    Hi! I give some ideas to improve this nice tutorial lessons: first I renamed Segment -> Border, Polygon -> Road, Envelope -> RoadShape. The road class owns its road shape. The shape is used for rendering the ground and knowing if a point is inside (in the current Radu's code, when splitting segments, the polygon vertices are not updated, it's ok because it's used only once). Instead of World having borders, I store them in the Road class (more logic: a road has borders ^^), I spread the breaking/union segment/polygon functions into Road and Editor classes to be more logic (Roads: containsSegment, breakRoads; Editor: breakAllRoads, keptSegments). Now the big change is in the union function: 1/ instead of returning kept borders: better to store them directly in the roads we are iterating, 2/ removed borders can be reused: and stored in roads to make road junctions shape (new class). 3/ For the moment I did not make more changes, BUT it's maybe interesting to: a) convert list of kept/unkept borders into a polygon class (instead of painting X segments, we paint a polygon), (b) a road will then be defined as chunks of polygons (road and junction), c) now, with this kind of structure, it may be help (IA) algorithms since we can know in which chunks of the rod a car is (beware a car maybe in several road junctions at the same time). Inside a road junction, we can refer to the graph structure of roads to know where to turn: In Radu's video of IA car, I recommend placing the (x,y) position of the car in the middle of its rear wheels (a car is the defined by its wheelbase, back and front overhang), knowing car corners are easy (for collision detection). Hope this will give new ideas :)

    • @Radu
      @Radu  9 місяців тому +1

      Hope more people find your nice comment. They are all things that sound good and can be tried. Let's pin your comment.

  • @ivgadev
    @ivgadev Рік тому +19

    Best programming series ever 😬

  • @Frankslaboratory
    @Frankslaboratory Рік тому +4

    You can just do anything you want with code. Thank you for teaching us, every project you make is unique and very impressive.

    • @Radu
      @Radu  Рік тому +1

      Thanks, Frank :-) Just wait until you see Phase 3!

    • @javifontalva7752
      @javifontalva7752 Рік тому +1

      I am flabbergasted!!! Thanks!!

    • @Radu
      @Radu  Рік тому

      :-)

  • @superboxes69
    @superboxes69 6 місяців тому +1

    The way you explain everything in such a simple way is amazing!

    • @Radu
      @Radu  6 місяців тому

      Thank you so much :-)

  • @serveshchaturvedi2034
    @serveshchaturvedi2034 Рік тому +5

    This just keeps getting better and better 🌞🎊🤩

    • @Radu
      @Radu  Рік тому

      Glad you think so :-)

  • @billallwell6507
    @billallwell6507 Рік тому +2

    Your programming and teaching style is masterful

    • @Radu
      @Radu  Рік тому

      Thank you!

  • @Radu
    @Radu  Рік тому +7

    Would you design the roads differently? How? :-)

    • @shaddow11ro
      @shaddow11ro Рік тому

      I dont think there is an better way then this!

    • @cloudzero2049
      @cloudzero2049 Рік тому +2

      If I were to do this with the knowledge I already have it wouldn't be as good. I once made an object editor that was similar to what you had at the end of the "polygon class" section, but I had an activation key that would only construct the object after the button was pressed. Also as a side note, needing to figure out distance and the use of atan2 for making games lead me to learning trigonometry (I still don't 100% understand atan2 lol).

    • @pizdaxyu
      @pizdaxyu Рік тому

      maybe by creating a segment between point A and B which is direct line and then allowing to additional points to be added on the segments to move around obstacles.

    • @Radu
      @Radu  Рік тому

      Yeah... many improvements come with practice. The more you code, in general, the better you are at solving problems and combining things together. My prerequisite on vectors (I think) teaches atan2. If not, it is the one on trigonometry. I recommend having a look if doubts.

    • @kalpaklokhande8619
      @kalpaklokhande8619 Рік тому +1

      After your initial self driving car tutorial. I wanted to make a race course where multiple of these self driving cars can race around. So I used bezier curves for curves and instead of getting borders like this, I put points on the segment and then got it's normal on both sides and saved it. Giving me a interior border and exterior border of the race track!
      P.s :- these two points on either side of the track also gave me the opportunity to create reward gates for my cars. To calculate who's in front too! It's amazing how everything just fits in the end!!
      I managed to create a few real life race tracks like Monaco, Qatar and Monza!!
      I actually have nothing to do with coding, but because of people like you. Sebastian Lague and a few other mind bogglingly creative people made me fall in love with programming and now I just can't stop. Can't wait for phase 3!!!

  • @TORMENTUMM
    @TORMENTUMM Рік тому +1

    How it evolves graphicallly as you improve the code is really cool.

    • @Radu
      @Radu  Рік тому

      Glad you think so :-)

  • @awekeningbro1207
    @awekeningbro1207 Рік тому +3

    Finally! I've been waiting for this new release

    • @Radu
      @Radu  Рік тому +1

      Thanks for waiting :-)

  • @Biongar
    @Biongar Рік тому +3

    Amazing work, thank you for every lesson!

    • @Radu
      @Radu  Рік тому +1

      Thank you for watching them!

  • @pesterenan
    @pesterenan Рік тому +5

    The final result is so incredible, I was typing together, and seeing the progress, but the final result is really awesome! It looks like an editor from Cities Skylines hahahah I can't wait for the next episodes! Awesome work Radu!

    • @Radu
      @Radu  Рік тому +1

      :-) hope you'll like what comes next!

  • @___d3p1
    @___d3p1 Рік тому +1

    What a creative way to generate the envelope of the roads (and also, to determine when a point is inside or outside a poly)! I am loving the progress of this app!

    • @Radu
      @Radu  Рік тому +1

      Thank you :-) any luck with the undo / redo?

    • @___d3p1
      @___d3p1 Рік тому +1

      Hello Radu! Unfortunately, I haven't had the chance to dive into the development as I initially intended. At this moment, I am following the implementation as you work on it, but I will try to proceed with the development as soon as I can

    • @Radu
      @Radu  Рік тому +1

      I'm sure you will :-) good thing about these videos, there's no deadline or anything like that!

  • @imonraj
    @imonraj 11 місяців тому +1

    FANTASTIC FANTASTIC WONDERFUL SERIES ❤❤❤

    • @Radu
      @Radu  11 місяців тому +1

      Really happy to hear you like it :-)

  • @ourwasvu
    @ourwasvu Рік тому +1

    best content ever !! simply AMAZING
    please for the second time keep going with
    Math& Code Fundamentals series , its help me with my final year project

    • @Radu
      @Radu  Рік тому

      I will probably continue that series someday, but not anytime soon. My upload schedule is pretty much fixed for the next year.

  • @pizdaxyu
    @pizdaxyu Рік тому +1

    very confusing about finding intersections, cleaning out break points and conjoining outlines.... but then again I'm dumb at math. Great work overall, can't wait for next episode

    • @Radu
      @Radu  Рік тому

      There are several ways to do this... I chose this way because we found intersections already in phase 1, so, one 'tool' should already be known.

    • @pizdaxyu
      @pizdaxyu Рік тому

      @@Radu the way you explain logic is easy to understand. I can easily repeat it. My personal issue is with trigonometry functions such as plus this minus that and divide by whatever is what confuses me. But don't mind me since I am sure most of your class are well versed in geometry.

    • @Radu
      @Radu  Рік тому

      I have a feeling you know more than you think :-) Some things, like trigonometry, do become easier with practice.

  • @aipt32
    @aipt32 Рік тому +4

    First of all. Thanks a lot for your great videos.
    I really enjoy this series and come back to your math lessons regularly.
    But I was wondering why you don't use ES modules in this series?
    It kind of bothers me to have all those classes and variables in the global scope. I also don't like having all those script tags.
    I think having a single entry file and importing and exporting the rest would make the code much cleaner. Another benefit would be better editor support like autocomplete and jump to definition.
    Is there a reason why you are not using it, or do you plan to refactor it later?

    • @Radu
      @Radu  Рік тому +10

      Here's an answer: I don't want to force people to use a local server... or for them to get the impression that you need VS Code and the live server extension to do it. Also, sometimes I take samples like this to show in class (at work or on 'teaching trips', on different computers, and they just run on the fly, no need to set anything up (and the computers require admin rights to set stuff up).
      Now here's the honest answer. I know modules are good and that the code is much nicer with them. But I haven't used them much and I don't want to teach something stupid. I normally teach just the things I understand really well.

  • @quentinquadrat9389
    @quentinquadrat9389 Рік тому +1

    Nice ! This is kind of methods I did not though that made me glue in my project. I'll thieve this :) Do you know OpenDRIVE specification 1.6.1 ? They give a nice specification on how they describe real roads.

    • @Radu
      @Radu  Рік тому +1

      I've heard about it but never studied it. I'm sure they deal must deal with more complex things like how wide the roads are, how many lanes and so on.

    • @quentinquadrat9389
      @quentinquadrat9389 Рік тому +1

      @@Radu yes this is made for dealing with complex but real road shapes. esmini (Environment Simulator Minimalistic) displays this format. It was just for information. Good job !

    • @Radu
      @Radu  Рік тому

      Good to know! Thanks :-)

  • @redgood5879
    @redgood5879 Рік тому +4

    perfect

    • @Radu
      @Radu  Рік тому +1

      You think so? :-)

    • @redgood5879
      @redgood5879 Рік тому +1

      @radu i was a bit excited the new video published
      all of your videos are exciting but this series really fits me 😀
      but it'll be cool if you publish the videos a bit more frequently :(

    • @Radu
      @Radu  Рік тому

      It would :-D but I can't...
      Been doing 1 video per week for the past 2 years or so and that's my limit. If anything, I will probably take things slower soon (this is not my 'real job').

    • @redgood5879
      @redgood5879 Рік тому +1

      @@Radu your videos are great
      its really great that you teach people without any expectation
      sorry if i bother you

    • @Radu
      @Radu  Рік тому

      Thanks :-)

  • @tomdeu79
    @tomdeu79 Рік тому +1

    Hey Radu when do you do my monkey theorem? i believe in you!

    • @Radu
      @Radu  Рік тому

      Really not sure about that :-D someday!

  • @devperatetechno8151
    @devperatetechno8151 Рік тому +1

    i felt kind of lost in this one with all the applied math over the polygons and segments, i mean hard to draw in my mind what the code were doing
    on the other hand i understand pretty clear all the work you did with points

    • @Radu
      @Radu  Рік тому

      Do you think a rewatch would help? Or the explanation was not good enough?

    • @devperatetechno8151
      @devperatetechno8151 Рік тому +1

      @@Radu maybe, but there is a lot to process mentally, probably is just me getting old jaja, besides that i think the graphic you create to show what math you were doing counting pair and odds interceptions help me a lot to slowdown the mental load, thanks for asking btw, greetings

    • @Radu
      @Radu  Рік тому +1

      Yeah, I was watching the video and thought that without the graphic it's really hard to understand. Don't give up :-)

  • @javifontalva7752
    @javifontalva7752 11 місяців тому +1

    For some reason I can see a polygon inside another polygon on the first segment. is that normal??

    • @javifontalva7752
      @javifontalva7752 11 місяців тому +1

      I am stupid. I had an envelope create in index.html. silly me!!

    • @Radu
      @Radu  11 місяців тому

      Good you found the fix!

  • @lionelgibaudan3592
    @lionelgibaudan3592 10 місяців тому +1

    Hello Radu, at @4:30 on the beginning of the video, the first time I'm testing the polygon, I get an infinite loop in the browser.
    The line "new Polygon(graph.points).draw(ctx);" in the animate() function from index.html is running again and again...
    The blue polygon is drawn correctly but the code loops again and again and the code inside polygon.js is executed again and again. event if I just put one console.log only in the class
    function animate() {
    viewport.reset();
    graphEditor.display();
    new Polygon(graph.points).draw(ctx);
    requestAnimationFrame(animate);
    }

    • @Radu
      @Radu  10 місяців тому

      Hi, I'm not sure I understand. The polygon is supposed to be created and displayed many times per second. It is supposed to loop, inside the animate function, for testing.

    • @lionelgibaudan3592
      @lionelgibaudan3592 10 місяців тому +1

      @@Radu ohh sorry, it was a misunderstanding from me, I didn't grab at first the exact meaning of the request animation frame.
      I've dropped a console.log into the polygon.js file just for control purposes and I was surprised that it looped again and again but in fact it's normal... I've also checked with your code, it's the same behaviour... 😉

  • @peryMimon
    @peryMimon 3 місяці тому

    why not to use arc for make the connection between the segments smooth ? It could be saved a lot of processing

    • @Radu
      @Radu  3 місяці тому

      Because, later, I do collision detection with those bounds and I wanted to keep the math simple and reuse the segment intersection code from phase 1.

  • @backstabba
    @backstabba Рік тому +1

    I believe that in this version, there is a bug with when you remove everything. The program is terminated after getIntersection fails due to undefined variables. Anyways, I am starting to write a Typescript version and will remedy this when done.

    • @Radu
      @Radu  Рік тому

      Hi, I tried to reproduce the problem but couldn't... If there are no segments (removing everything) the loop just doesn't do anything...
      Good luck with the Typescript implementation :-)

    • @backstabba
      @backstabba Рік тому +1

      @@Radu It is probably a type error then. Either way, a single if should solve it :)

    • @Radu
      @Radu  Рік тому

      @@backstabba 👍

    • @eduardorojas2525
      @eduardorojas2525 8 місяців тому

      poly is undefined if you remove everything, you need make this in generate method:
      if (this.envelopes.length >= 2 && this.envelopes[0] && this.envelopes[1]) {
      this.intersections = Polygon.break(
      this.envelopes[0].poly,
      this.envelopes[1].poly
      );
      }

  • @ddodoobird
    @ddodoobird Рік тому +1

    Coding with Radu!

    • @Radu
      @Radu  Рік тому +1

      Let's code now

  • @ChandrashekarCN
    @ChandrashekarCN Рік тому +1

    💖💖💖💖

  • @vincentcleaver1925
    @vincentcleaver1925 Рік тому +1

    It's showing me the glaring mistakes I'm making in constructors

    • @Radu
      @Radu  Рік тому

      I'm not sure I understand your comment. Some difficulties with the code?

    • @vincentcleaver1925
      @vincentcleaver1925 Рік тому +1

      Nope. In the coder, me.

    • @Radu
      @Radu  Рік тому

      @@vincentcleaver1925 :-)