designcoding
Search
About Table of Contents Keywords Support designcoding!

Vector Normalization and Dot Product

October 29, 2021 | 7,103 views
Design Mathematics | Linear Algebra | Rhino Python
dot product | unit vector | vector | vector normalization

This is the continuation of the Vector class we started here, and further advanced here, here, and here. This new Rhino Python implementation is mostly educational and partially a hobby. Before this session, we have developed display, magnitude, add, multiply, reverse, and subtract methods. This time, I am adding the vector normalization and dot product methods and seeing the utilizations of the dot product.

import rhinoscriptsyntax as rs
import math
class Vector:
	def __init__(self, point):
		self.components = point
	def display(self, origin=[0,0,0]):
        v = self.components
        tip = (v[0]+origin[0], v[1]+origin[1], v[2]+origin[2])
        line = rs.AddLine(origin, tip)
        rs.CurveArrows(line, 2)
	def magnitude(self):
		v = self.components
		result = v[0]**2 + v[1]**2 + v[2]**2
		return math.sqrt(result)
	def add(vA, vB):
		v1 = vA.components
		v2 = vB.components
		addition = (v1[0]+v2[0], v1[1]+v2[1], v1[2]+v2[2])
		return Vector(addition)
	def multiply(self, s):
		v = self.components
		return Vector([v[0]*s, v[1]*s, v[2]*s])
	def reverse(self):
		return self.multiply(-1)
	def subtract(vA, vB):
		return Vector.add(vA, vB.reverse())
	def normalize(self):
		return self.multiply(1/self.magnitude())
	def dot(vA, vB):
		v1 = vA.components
		v2 = vB.components
		return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]
LineExplanation
1-26Already explained in the previous posts.
27Define a new method called “normalize”.
28Call the multiply method for the given vector (self), with the scalar of 1/magnitude. This will reduce the length to 1. Imagine a vector with a length of A. Multiplying it with 1/A would result in 1.
29Define a new class method called “dot”. This method takes two vector objects.
30To make the code lines shorter, create a temporary variable called v1 and store the components (list of three numbers) of the first input vector.
31Create a temporary variable called v2, and store the components (list of three numbers) of the second input vector.
32Calculate the dot product (which is a single number) and return it to the user whenever it is called

In the above code, I created a new method for vector normalization, called normalize(). Since we developed a vector-scalar multiplication method earlier, now we can use it to reduce (or increase) the magnitude (length) of any vector to 1 unit. Therefore, the method multiplies the given vector by 1 / its magnitude.

vector normalization and dot product

Then, I developed a simple dot product method. The above diagram shows the formula for two-dimensional vectors. Therefore, you can generalize it to n-dimensional vectors by the same formula. Finally, to have a good insight on the dot product I highly recommend watching this and this.

  • Search

  • Categories

    • Education
      • Basic Design
      • Design Geometry
      • Design Mathematics
      • Digital Fabrication
      • Parametric Modeling
      • Tutorials
    • Philosophy
      • Analytical Tradition
      • Phenomenology
    • Practice
      • 3D Models
      • Projects
      • Publications
      • Workshops
    • Research
      • 3D Printing
      • Building Facade
      • Calculus
      • Climate Analysis
      • Compass Constructions
      • Computational Geometry
      • Curves
      • Decorative Arts
      • Digital Fabrication
      • Evolutionary Solvers
      • Folding Structures
      • Fractals
      • Graph Theory
      • Interlocking Structures
      • Islamic Patterns
      • Linear Algebra
      • Minimal Surfaces
      • Muqarnas
      • Non-Euclidean Geometry
      • Paneling
      • Parametric Curves
      • Parametric Objects
      • Parametric Surfaces
      • Pattern Deformations
      • Patterns
      • Pavilions
      • Polyhedra
      • Rammed Earth Structures
      • Robotic Fabrication
      • Shape Grammars
      • Simulation
      • Space Syntax
      • Surface Constructions
      • Tessellations
      • Tools
      • Vector Fields
      • Virtual Reality
    • Tools and Languages
      • 3DS Max
      • 3DS Max Script
      • Grasshopper
      • Photoshop
      • Physical Prototyping
      • Revit
      • Rhino
      • Rhino Macro
      • Rhino Python
      • Rhino Script
      • Unity
  • Monthly Archive

    • August 2026 (1)
    • October 2025 (1)
    • June 2025 (2)
    • May 2025 (2)
    • April 2025 (5)
    • December 2024 (40)
    • August 2024 (5)
    • July 2024 (6)
    • April 2024 (4)
    • March 2024 (10)
    • February 2024 (10)
    • January 2024 (8)
    • December 2023 (10)
    • August 2023 (3)
    • July 2023 (3)
    • June 2023 (7)
    • May 2023 (8)
    • April 2023 (7)
    • March 2023 (2)
    • February 2023 (2)
    • January 2023 (3)
    • December 2022 (6)
    • November 2022 (7)
    • January 2022 (1)
    • December 2021 (1)
    • October 2021 (3)
    • September 2021 (4)
    • August 2021 (4)
    • May 2019 (2)
    • April 2019 (1)
    • March 2019 (5)
    • January 2019 (2)
    • December 2018 (1)
    • November 2018 (4)
    • October 2018 (9)
    • July 2018 (1)
    • June 2018 (3)
    • May 2018 (1)
    • April 2018 (4)
    • February 2018 (2)
    • January 2018 (7)
    • August 2017 (9)
    • July 2017 (6)
    • October 2016 (1)
    • May 2015 (5)
    • April 2015 (8)
    • March 2015 (12)
    • February 2015 (4)
    • January 2015 (11)
    • November 2014 (1)
    • August 2014 (1)
    • June 2014 (2)
    • May 2014 (12)
    • April 2014 (5)
    • March 2014 (3)
    • February 2014 (6)
    • January 2014 (4)
    • December 2013 (5)
    • November 2013 (11)
    • October 2013 (2)
    • September 2013 (9)
    • August 2013 (4)
    • July 2013 (2)
    • June 2013 (14)
    • May 2013 (4)
    • April 2013 (10)
    • March 2013 (11)
    • February 2013 (11)
    • January 2013 (10)
    • December 2012 (10)
    • November 2012 (6)
    • October 2012 (13)
    • September 2012 (2)
    • August 2012 (5)
    • July 2012 (14)
    • June 2012 (6)
    • May 2012 (17)
    • April 2012 (15)
    • March 2012 (9)
    • February 2012 (16)
    • January 2012 (18)
    • December 2011 (20)
    • November 2011 (2)
  • Support designcoding!

    Enjoying designcoding? Support its future with a small donation on Patreon. Thank you!

    Patreon


    copyright 2026 designcoding.net | about | table of contents | keywords | privacy policy | end user license agreement