Collapse
CollapsingX
  • - or -

Transforming from one coordinate system to another


Points can be transformed from one coordinate system to another using the TRANSFORMCOORDINATES function.

Consider, for example, how the same point has 4 different sets of coordinates depending on the coordinate system (fixture) with which the coordinates are expressed.

Using TRANSFORMCOORDINATES and accessing individual coordinates

After you transform a point between coordinate systems, you might need to access its X- or Y-coordinate separately (for example, trying to display a coordinate of a point in an operator view's Value element, or using it in a reconfiguration operation). This cannot be done directly.

Although TRANSFORMCOORDINATES can take and return a point object, you cannot create a variable of type Point to hold the object for easy retrieval of its coordinates (only variables of type Point array are possible). To extract the coordinates separately, you need to place the point in an array. Once in an array, you can use the SELECT and the ELEMENTAT functions together to extract the X- or Y-coordinate of the point.

You can pass TRANSFORMCOORDINATES a point object and then place its resulting point object in an array. Alternatively, you can pass TRANSFORMCOORDINATES an array containing the point, and it will return the resulting point in a point array.

Passing the source point as a point object

When you pass TRANSFORMCOORDINATES a point object containing the point to transform (for example, using the POINT function), it returns the transformed point in a point object. To access the individual X- and Y-coordinates of the transformed point, you must then convert the results to a point array and use the SELECT and ELEMENTAT functions.

ELEMENTAT( SELECT( [ TRANSFORMCOORDINATES( POINT(10,25), PixelToAbsolute, Flowcharts("MainFlowchart").Camera.Image) ], Item.X), 1)

The individual parameters of the TRANSFORMCOORDINATES function are:

  • SourceCoordinates = POINT(10,25)
  • TransformationType = PixelToAbsolute
  • CalibratedImage = Flowcharts("MainFlowchart").Camera.Image

The data type of the output of TRANSFORMCOORDINATES is the same as the data type of its first parameter, the SourceCoordinates parameter. In this case, since SourceCoordinates is a point object, the output of the TRANSFORMCOORDINATES function is a point object, which can then be placed in a point array using the [] operator.

The SELECT function takes an array and an expression, and returns an array after applying the expression to each element of a source array. In this case, Item.X will return the X-coordinate of the point object, so the function outputs the X-coordinate of the point object in an array: [10].

The ELEMENTAT function takes an array and an index, and returns the element at that index. In this case, it returns the numeric value 10.

Passing the source point in a point array

Since the TRANSFORMCOORDINATES function supports multiple data types, an equivalent approach is to use POINTARRAY to produce a point array containing the coordinates, and pass it to the TRANSFORMCOORDINATES function. This function will then return the transformed coordinates in a point array. You can then use the SELECT and ELEMENTAT functions on this array.

The following example does this and returns the X-coordinate, in the absolute coordinate system, of the top-left corner of a region.

ELEMENTAT( SELECT( TRANSFORMCOORDINATES( POINTARRAY([IntensityChecker.TestRegion.TopLeftX], [ItensityChecker.TestRegion.TopLeftY]), RelativeToAbsolute, IntensityChecker.TestRegion.CoordinateSystem), Item.X), 1)

The individual paramters of the TRANSFORMCOORDINATES function are:

  • SourceCoordinates = POINTARRAY([IntensityChecker.TestRegion.TopLeftX], [ItensityChecker.TestRegion.TopLeftY])
  • TransformationType = RelativeToAbsolute
  • CalibratedImage = IntensityChecker.TestRegion.CoordinateSystem

Since the output data type of TRANSFORMCOORDINATES is already a point array, the [] operator is not needed to pass the result to the SELECT function.

In this case, the SELECT and ELEMENTAT functions perform the same roles as in the example in the Passing the source point as a point object subsection of this section.