designcoding
Search
About Table of Contents Keywords Support designcoding!

Derivative and Slope

April 6, 2018 | 4,595 views
Calculus | Rhino Python
calculus | derivative | graph | normal | parametric | slope

Yes, interesting topics started to reveal themselves, when I dig into the function curves, especially in the parametric representation. The first interesting application is the “derivative”. Nobody in high school told me that the derivative of a function at a given point gives the slope of the graph at that point. Moreover, it is possible to convert the slope value into an angle in degrees, showing the angle of the tangent line to the x-axis at that point. They are very interesting and intuitive for me to understand the deep relationship between maths and all computational tools designers use today. Below is the simplest possible Python script that calculates the slope and tangent angle at a given point of a parametric function graph. It also visualizes the outputs (if you don’t believe me). There are a lot more topics in this and other fields of math, that are waiting to be studied.

Of course, I only approximate the derivative calculation by using a very very small number for “dt”, escaping from the limits. The formula for calculating the derivative is very interesting. I love the elegance of f(x + dx) there… I couldn’t keep myself from drawing that;

# Slope of Parametric Functions
import rhinoscriptsyntax as rs
import math
def f(t): return 3 * math.sin(t)
def g(t): return - 4 * t
def derivativeF(t,dt): return (f(t + dt) - f(t) ) / dt
def derivativeG(t,dt): return (g(t + dt) - g(t) ) / dt
def evaluate(t):
	# Evaluate f(t),g(t) and place a point on f(t),g(t)
	point = (f(t),g(t),0)
	print "Parametric function is evaluated at t =",t
	print "Resulting point is at",point
	rs.AddPoint(point)
def graph(t0,t1,dt):
	# Draw a graph of f(t),g(t) by given domain and step size
	points = []
	t = t0
	while t <= t1:
		points.append((f(t),g(t),0))
		#evaluate(t)
		t = t + dt
	points.append((f(t1),g(t1),0))
	rs.AddPolyline(points)
	print "Domain of t is",t0,"to",t1
	print "Number of samples used:",len(points)
def slope(t,dt):
	# Slope is the instantaneous ratio of vertical change to horizontal change (dy / dx) at a point
	# In a parametric function, slope is dy / dx = (dy / dt) / (dx / dt)
	dF = derivativeF(t,dt)
	dG = derivativeG(t,dt)
	d = dG / dF
	print "Slope is",round(d,3),"at t =",t
	# Slope of f(t),g(t) indicates the direction of its graph
	if d > 0: print "Graph increases from left to right at t =",t
	if d < 0: print "Graph decreases from left to right at t =",t
	if d == 0: print "This is a constant function"
def tangent(t,dt):
	# Tangent is the direction given by the slope
	start = (f(t),g(t),0)
	dF = derivativeF(t,dt)
	dG = derivativeG(t,dt)
	d = dG / dF
	angle = math.degrees(math.atan(d))
	end = rs.Polar(start, angle, 6)
	curve = rs.AddLine(start,end)
	rs.CurveArrows(curve,2)
	# Slope is the tangent result of the angle between the tangent line and x axis
	print "Tangent angle is",round(angle,3),"to the x-axis at t =",t
def normal(t,dt):
	# Normal is the direction perpendicular to tangent
	start = (f(t),g(t),0)
	dF = derivativeF(t,dt)
	dG = derivativeG(t,dt)
	d = dG / dF
	angle = math.degrees(math.atan(d))
	end = rs.Polar(start, angle + 90, 6)
	curve = rs.AddLine(start,end)
	rs.CurveArrows(curve,2)
	print "Normal angle is",round(angle + 90,3),"to the x-axis at t =",t
graph(-2,2,0.01)
slope(1,1/10000)
tangent(1,1/10000)
normal(1,1/10000)

The above drawing is for an explicit function graph (y = f(x) style). In a parametric curve, the overall derivative is calculated by dividing the derivatives of g(t) and f(t). You’ll notice that in the Python code.

  • 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