Adding x amount of lines

Hi there

I’m currently working on a simple alignment script that is pretty similar to PerspectiveMatch for when we have a photogrammetry model of a site and a satellite photo. What I’d like to do is to set a x amount of vectors between points on the Photogrammetry mesh and between the Satellite photo and then calculate the average of all the vectors and to move the mesh accordingly, this would allow for a slightly better alignment than by doing it by eye as we currently do.

I’ve run into two issues within this.

  1. How do I create an average vector from a list of vectors?
  2. How do I make it possible for the user to set x amount of vectors, preferably live, like in PerspectiveMatch

Here’s where I’m at currently:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math

drone = rs.GetObject("Select Mesh")
num = 3

vecPairs = []

for x in range(num):
    line = rs.GetLine(1,message1 = "Select Point on Mesh", message3 = "select Point on SAT")
    vecDir = line[1] - line[0]
    vecPairs.append(vecDir)


trans  = sum(vecPairs) / ln(vecPairs)

rs.MoveObject(drone, trans) 

Okay so I’ve solved the Vector addition issue, though there’s probably a more elegant way of doing it. I’d love to figure out how to create a dynamic display of all the vectors and how to allow the user to decide when he’s added enough vectors as he’sadding them.

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math

drone = rs.GetObject("Select object to move")


num = int(rs.GetReal('number of vectors',5))
totalVect = Rhino.Geometry.Vector3d(0,0,0)

for x in range(num):
    line = rs.GetLine(1,message1 = "Select point on object", message3 = "select point on destination")
    vecDir = line[1] - line[0]
    totalVect = totalVect + vecDir


trans  = totalVect / num

rs.MoveObject(drone, trans) 

Hi @rheinason, you could use a CustomDisplay for it like in below example:

import Rhino
import rhinoscriptsyntax as rs

def AverageVector(vectors):
    v = vectors[0]
    for vec in vectors[1:]: v += vec
    return v/len(vectors)

def DoSomething():
    display = Rhino.Display.CustomDisplay(True)
    color   = Rhino.ApplicationSettings.AppearanceSettings.FeedbackColor
    msg1, msg3 = "Select point on object", "Select point on destination"
    vectors = []
    
    while True:
        points = rs.GetLine(1, None, msg1, None, msg3)
        if not points: break
        
        vector = points[1] - points[0]
        vectors.append(vector)
        
        display.AddVector(points[0], vector, color, True)
    
    display.Enabled = False
    if len(vectors) >= 1: print AverageVector(vectors)
    
DoSomething()

Taken above example, just press Enter, Space or use right mouse button.

_
c.

1 Like

Impressively concise! Thank you!