# Moving the midpoint of a curve perpendicularly to the curve

Hello!
I just returned back to programming in Python in Grasshopper! And I am working on a new project: the Koch Curve. However, I can’t seem to solve this problem: moving the midpoint of a curve perpendicularly (the point is supposed to be moved in 2-dimensional space).

The solution I came up with, which, unfortunately, doesn’t deliver my wished result is:

``````import rhinoscriptsyntax as rs
from math import sqrt

length = rs.CurveLength(input_crv)
distance = length/3
midpoint = rs.CurveMidPoint(input_crv)
distance_to_move = distance * sqrt(3)/2
x = distance_to_move / rs.CurveLength(input_crv)

endpoint = rs.CurveEndPoint(input_crv)

vector1 = rs.VectorCreate(midpoint, (0,0,0))
vector2 = rs.VectorCreate((0, x, 0), midpoint)
vector3 = rs.VectorCreate((0, 1, 0), midpoint)

product = rs.VectorCrossProduct(vector1, vector2)
vector_move = rs.VectorCrossProduct(product, vector3)

top_point = midpoint + vector_move

a = top_point
midpoint = midpoint
``````

This makes the most sense for me mathematically, but I also just started learning and looking at vectors quite recently, so I am open to any additional information or guidance you might provide me with!

Michalina

Hi,

I would do AM cross Z and scale the vector by the distance.

``````import rhinoscriptsyntax as rs
from math import sqrt

length = rs.CurveLength(input_crv)
distance = length/3
midpoint = rs.CurveMidPoint(input_crv)

endpoint = rs.CurveEndPoint(input_crv)

vector1 = rs.VectorCreate(endpoint, midpoint)

product = rs.VectorCrossProduct(vector1, (0,0,1))
product = distance * rs.VectorUnitize(product)

top_point = midpoint + product

a = top_point
midpoint = midpoint
``````

1 Like

Thank you so much! This solution is very elegant and makes much more sense!
Now, I will be able to continue trying to create the Koch curve in Python.