Forum

Author Topic: Coordinates system influence on chunk rotation matrix  (Read 2366 times)

Yoann Courtois

  • Sr. Member
  • ****
  • Posts: 316
  • Engineer in Geodesy, Cartography and Surveying
    • View Profile
Coordinates system influence on chunk rotation matrix
« on: May 07, 2019, 04:26:02 PM »
Hi everyone,

Within my automated pipeline, I've developed a method that calculate and set the smallest bounding box which included a "project contour" polygon.
The calculation has been separated in 3 steps :
- Set the bounding box center
- Set the bounding box size
- Set the bounding box orientation

Everything works very fine until today ... when I decided to include coordinates system in my pipeline.
Indeed, in "Local Coordinates" ('LOCAL_CS["Local Coordinates",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'), everything is OK,
but when I use projected coordinates system (For exemple EPSG::3946 in France), the box orientation doesn't work anymore (Center and size are OK !)...

Here is the following code for bounding box orientation setting (Where vertex_a / vertex_b / vertex_c are the corners of my minimum rotated rectangle that include my polygon) :
Code: [Select]
    cos_teta = (vertex_c.x - vertex_a.x) / vertex_a.distance(vertex_c)
    sin_teta = (vertex_c.y - vertex_a.y) / vertex_a.distance(vertex_c)

    __pseudo_region.rot = [[sin_teta, -cos_teta, 0],
                           [cos_teta, sin_teta, 0],
                           [0, 0, 1]]

    chunk.region.rot = chunk.transform.matrix.rotation().inv() * __pseudo_region.rot

After some investigation, my pseudo_region hasn't changed, so the problem is coming from the chunk rotation matrix (chunk.transform.matrix.rotation()).
I cannot understand how chunk.crs has inlfuenced the chunk.transform matrix... and have no idea how to fix the problem...

Regards
--
Yoann COURTOIS
R&D Engineer in photogrammetric process and mobile application
Lyon, FRANCE
--

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Coordinates system influence on chunk rotation matrix
« Reply #1 on: May 12, 2019, 02:31:35 PM »
Hello Yoann,

In which coordinate system space you are defining the bounding box orientation with pseudo_region.rot?
Best regards,
Alexey Pasumansky,
Agisoft LLC

Yoann Courtois

  • Sr. Member
  • ****
  • Posts: 316
  • Engineer in Geodesy, Cartography and Surveying
    • View Profile
Re: Coordinates system influence on chunk rotation matrix
« Reply #2 on: May 15, 2019, 10:12:15 AM »
Hello Alexey,

My pseudo_region is calculated in georeferenced coordinates, so previously in "Local coordinates" but now in a projected coordinate system.

Then, I apply some transformation to set the chunk.region in his chunk coordinate system :
- To reproject the region center :
Code: [Select]
chunk.transform.matrix.inv().mulp(chunk.crs.unproject(__pseudo_region.center))
- To scale the region size :
Code: [Select]
chunk.region.size = (__pseudo_region_long / chunk.transform.scale,
                     __pseudo_region_larg / chunk.transform.scale,
                     __pseudo_region_haut / chunk.transform.scale)

- To convert the region rotation :
Code: [Select]
chunk.region.rot = chunk.transform.matrix.rotation().inv() * __pseudo_region.rot
Everything works fine for the center and the size, but not for the rotation...
--
Yoann COURTOIS
R&D Engineer in photogrammetric process and mobile application
Lyon, FRANCE
--

Yoann Courtois

  • Sr. Member
  • ****
  • Posts: 316
  • Engineer in Geodesy, Cartography and Surveying
    • View Profile
Re: Coordinates system influence on chunk rotation matrix
« Reply #3 on: May 15, 2019, 10:19:41 AM »
Notice that since last week, I found a work-around by setting back the whole project in "Local coordinates", then calculating my box, and finally reprojecting the whole project in my projected coordinates system

But, besides I don't know if the double reprojection is really good, I would prefer find how to correct the region rotation conversion...
--
Yoann COURTOIS
R&D Engineer in photogrammetric process and mobile application
Lyon, FRANCE
--