Rotate/Scale/Shear a grid

From ObjectVision

Jump to: navigation, search

Configuration examples Rotate/Scale/Shear a grid

Introduction

The script presents an example how you can rotate, stretch and shear a raster domain.

Example

container parameters
{
	parameter<meter> gridsize := 1000[meter];
												
	parameter<meter> NL_grid_X_min := 270000[meter];
	parameter<meter> NL_grid_Y_min := 325000[meter];
	
	parameter<meter> X_org := (     0f + (NL_grid_Y_min / 2f))[meter];
	parameter<meter> Y_org := (375000f - (NL_grid_X_min / 2f))[meter];
	
	parameter<uint32> aantalkolommen := value(((NL_grid_Y_min + NL_grid_X_min)*(sqrt(2f) / 2f)) / gridsize, uint32);
	parameter<uint32> aantalrijen           := value(((NL_grid_Y_min + NL_grid_X_min)*(sqrt(2f) / 2f)) / gridsize, uint32);
	
	parameter<float32> shear_factor       := 0.5f;
	parameter<float32> rotation_angle    := (pi() / 4d)[float32];   // in radial=45 degrees 
	parameter<float32> X_stretch_factor := gridsize;
	parameter<float32> Y_stretch_factor := gridsize;
}

unit<fpoint> domain;	
unit<spoint> rotated_grid_domain := range(domain, point(0s, 0s), point(parameters/aantalkolommen[int16], parameters/aantalrijen[int16]));

unit<spoint> conversion_matrix := range(spoint, point(0s,0s), point(2s,2s))
,  Using = "parameters"
{
	attribute<float32> A_stretch  := union_data(., Y_stretch_factor, 0f, 0f, X_stretch_factor);
	attribute<float32> B_shear    := union_data(., 1f, shear_factor, 0f, 1f);
	attribute<float32> C_rotation := union_data(., cos(rotation_angle), sin(rotation_angle), -sin(rotation_angle), cos(rotation_angle));
	attribute<float32> AxB           := matr_mul(A_stretch, B_shear,.);
	attribute<float32> AxBxC       := matr_mul(AxB, C_rotation,.);
	attribute<float32> Result        := AxBxC;
}

unit<upoint> grid_coords := range(upoint, point(0,0), point(2, #rotated_grid_domain))
{
	attribute<float32> rotated_grid := union_data(., PointCol(id(rotated_grid_domain))[float32], PointRow(id(rotated_grid_domain))[float32]);
	attribute<float32> rd                 := matr_mul(conversion_matrix/Result, rotated_grid, .);
}

unit<uint32> grid_domain := range(uint32, 0, #rotated_grid_domain)
,  Using         = "parameters"
,  DialogData = "rotated_grid_rd"
,  DialogType = "map"
{ 
	attribute<rdc_meter> rotated_grid_rd  := point(first(grid_coords/rd, pointcol(id(grid_coords))[.]) + Y_org, last(grid_coords/rd, pointcol(id(grid_coords))[.]) + X_org, geography/rdc_meter);
}
Personal tools