Forum

Author Topic: Wrong marker position when using transform.matrix  (Read 957 times)

Tom2L

  • Newbie
  • *
  • Posts: 13
    • View Profile
Wrong marker position when using transform.matrix
« on: June 05, 2022, 04:47:42 PM »
Hi all,
I'd like to add markers in circle around bbox center of my model. the circle would turn around Z axis at custom altitude.
To do so, i have created a custom function that use model center as center of the circle and distance between center and corners as radius. It return df cointaing X and Y position of points around center.
Code: [Select]
def pic_in_circle(center_x, center_y, radius, snapshots_number):
    '''
    :param center_x: X coordinates of the center of the bbox   
    :param center_y: Y coordinates of the center of the bbox   
    :param radius: distance between corners and center of the bbox
    :param snapshots_number: number of markers to create
    :return: df containing X and Y coordinates of selected points with lenght based on number of snapshots
    '''
    arr=[]
    for i in range(360):
        x = center_x + radius*math.cos(i)
        y = center_y + radius*math.sin(i)
        #Create array with all the x-co and y-co of the circle
        arr.append([x,y])
    df = pd.DataFrame(arr)
    df.columns = ['X', 'Y']

    indexes = np.arange(0, len(df), step=(360/snapshots_number))
    df = df.iloc[indexes]
    return df

I call this function with :
Code: [Select]
circle = pic_in_circle(center.position[0], center.position[1], radius, 50) with center of the Bbox containing ref model is Vector([4.521869862724644, 50.6898008733669, 4.897874583534293])
It creates a df with X and Y position that are NOT in the same crs, such as :
             X           Y
0    38.008388 -199.830643
7    30.059443 -178.610007
14   10.125042 -167.834073
...
I now try to add those points to my project with :
Code: [Select]
for index, row in circle.iterrows():
    pos = Metashape.Vector((row['X'], row['Y'], 0))
    circleM = ref_model.addMarker()
    circleM.label = "circle " + str(index + 1)
    circleM.reference.location = ref_model.crs.project(ref_model.transform.matrix.mulp(pos))
    circleM.reference.enabled = True
    print(circleM.reference.location)

But it creates a circle that turn around Y axis instead of Z axis. What is weird is that i set altitude as 0 but it turns it into negative and positive values :
Vector([4.521858890254145, 50.68958594593813, 6.024067006404548])
Vector([4.5218386528562995, 50.68962537116644, 18.59051823922667])
Vector([4.521751947695833, 50.68971443077309, 25.186119392769566])

I suppose that my error came from the crs transform.matrix function but i'm unable to see what i did wrong. Could anyone help me ?
Code: [Select]
circleM.reference.location = ref_model.crs.project(ref_model.transform.matrix.mulp(pos))
Thanks a lot,
Thomas