14 มกราคม 2010Unit Vectors – Normalizing ใช้ python และ numpy

 

ก่อนที่เราจะ normalize vector ได้ เราต้องหา norm ( magnitude หรือ ขนาด) ของมันก่อน

ซึ่งมันหาได้โดยการ ถอด Square root ของ ผลบวกกำลังสองครับ (sumsquare)

    length = sqrt((ax * ax) + (ay * ay) + (az * az))
    length = sqrt(9 + 1 + 4) = 3.742

ซึ่ง 3.742 จะเป็น ขนาดของ Vector [1,2,3] ครับ

ถ้าจะ normalize  vector  นี้ก็เอา magnitude ไปหารทุกตัวครับ

    x = 3.0 / 3.742 = 0.802
    y = 1.0 / 3.742 = 0.267
    z = 2.0 / 3.742 = 0.534

 

ซึ่งใน python เขียนแค่

ก็จะได้คำตอบ

array([ 0.26726124,  0.53452248,  0.80178373])

การหา Norm (ขนาดของ  vector) และการทำ vector normalization และอื่นๆ (แบบละเอียด) จากต้นฉบับอ่านได้ที่  http://www.fundza.com/vectors/normalize/index.html เลยครับ


Tags: , , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
blog comments powered by Disqus
Get Adobe Flash playerPlugin by wpburn.com wordpress themes