Vector with Java Script

 Vector with Java Script



https://thecodingtrain.com/learning/nature-of-code/1.5-unit-vector.html


    Welcome to Vector with Java Script, for the start we're gonna be talking about normalize function, the scenario we're gonna talking about is simple, canvas, and some mover on the canvas, let's say the canvas is 600 by 400, then we have the mouse, you're moving the mouse somewhere, probably the corner of the 600 by 400 canvas, what we're looking to do is figure how do we calculate if we know the position the mover and the mouse's position, a vector that points from 1 to the other, if we want this particular particle to accelerate towards the mouse, how are we gonna calculate this vector? let's call it V, when I say calculate the vector, what we're really looking for is the X component and the Y component, so V dot X equals what? 580 minus 300, so that is gonna be 280,
V dot Y equals 200 minus 20, so it's gonna be 180, so the vector is 280 comma 180, what mathematical operation did I do here you may ask, there are 2 vectors really, we have this vector here called position, and the other vector will be called mouse, what we did is mouse minus position gives us V, V equals mouse minus position, let's confirm this really works the subtract operation by diagramming this, so if we take this mouse vector that's pointing from 0 to this location, 580 comma 200, if I were to add, if I were to say plus position I'll put these vectors end to end, if you want to see the rest go watch the video above, thank you for reading.

💓💓💓💓💓💓💓💓

ยินดีต้อนรับสู่  การเรียนรู้ Vector ด้วย Java Script สำหรับการเริ่มต้น เราจะพูดถึงฟังก์ชันนอร์มัลไลซ์ สถานการณ์ที่เราจะพูดถึงนั้นเรียบง่าย แคนวาส และตัวขับเคลื่อนบางส่วนบนแคนวาส สมมติว่าแคนวาสมีขนาด 600 x 400 แล้ว เรามีเมาส์ คุณกำลังเคลื่อนเมาส์ไปที่ใดที่หนึ่ง อาจเป็นมุมของผ้าใบขนาด 600 x 400 สิ่งที่เราต้องทำคือคิดหาว่าเราคำนวณอย่างไรถ้าเราทราบตำแหน่งผู้เสนอญัตติและตำแหน่งของเมาส์ เป็นเวกเตอร์ ที่ชี้จาก 1 ไปยังอีกอันหนึ่ง ถ้าเราต้องการให้อนุภาคนี้เร่งเข้าหาเมาส์ เราจะคำนวณเวกเตอร์นี้อย่างไร? เรียกมันว่า V เมื่อฉันพูดว่าคำนวณเวกเตอร์ สิ่งที่เรากำลังมองหา คือ องค์ประกอบ X และ องค์ประกอบ Y ดังนั้น V ดอท X เท่ากับอะไร? 580 ลบ 300 มันจะเท่ากับ 280 V ดอท Y เท่ากับ 200 ลบ 20 มันจะเท่ากับ 180 เวกเตอร์คือ 280 ลูกน้ำ 180 ฉันทำการคำนวณอะไรที่นี่ คุณอาจถาม มีเวกเตอร์ 2 ตัวจริงๆ เรามีเวกเตอร์นี่ตรงนี้เรียกว่าตำแหน่ง และอีกตัว เวกเตอร์จะถูกเรียกว่าเมาส์ สิ่งที่เราทำคือตำแหน่งลบของเมาส์ทำให้เรา V, V เท่ากับตำแหน่งลบของเมาส์ มายืนยันว่านี่ใช้งานได้จริงกับการดำเนินการลบโดยการสร้างไดอะแกรมนี้ ดังนั้นถ้าเราเอาเวกเตอร์เมาส์นี้ที่ชี้จาก 0 ไปยังตำแหน่งนี้ 580 ลูกน้ำ 200 ถ้าผมต้องบวก ถ้าผมบอกว่าตำแหน่งบวก ผมจะใส่เวกเตอร์เหล่านี้จนจบ ถ้าคุณอยากดูที่เหลือ สามารถดูวิดีโอด้านบน 


ความคิดเห็น