You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.7 KiB
118 lines
3.7 KiB
//----------------------------------------------------------------------------
|
|
// Laser Guard Ltd.
|
|
// Copyright © 2000-2002. All Rights Reserved.
|
|
// Version 1.0 01/01/2000
|
|
// Last modification: 08/10/2003
|
|
// PROJECT:
|
|
// SUBSYSTEM:
|
|
// FILE: Transform.cpp
|
|
// AUTHOR: Belkovsky Joseph
|
|
// OVERVIEW
|
|
// ~~~~~~~~
|
|
// Source file of Transform.cpp
|
|
//----------------------------------------------------------------------------
|
|
// Transform.cpp : Defines the entry point for the console application.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "..\LgLib\Version.h"
|
|
|
|
#include "transform.h"
|
|
|
|
const double transform_3::PI_M = 3.141592653589793;
|
|
const double transform_3::DTOR = 0.017453292519943;
|
|
const double transform_3::RTOD = 57.29577951308232;
|
|
|
|
vector_3::vector_3(double a0, double a1, double a2)
|
|
{
|
|
elem_[0] = a0;
|
|
elem_[1] = a1;
|
|
elem_[2] = a2;
|
|
}
|
|
|
|
matrix_3::matrix_3(double a00, double a01, double a02,
|
|
double a10, double a11, double a12,
|
|
double a20, double a21, double a22)
|
|
{
|
|
elem_[0][0] = a00; elem_[0][1] = a01; elem_[0][2] = a02;
|
|
elem_[1][0] = a10; elem_[1][1] = a11; elem_[1][2] = a12;
|
|
elem_[2][0] = a20; elem_[2][1] = a21; elem_[2][2] = a22;
|
|
}
|
|
|
|
matrix_3 matrix_3::operator * (const matrix_3& matrix) const
|
|
{
|
|
matrix_3 result;
|
|
|
|
for(__int8 ii = 0; ii < 3; ++ii)
|
|
for(__int8 jj = 0; jj < 3; ++jj)
|
|
for(__int8 kk = 0; kk < 3; ++kk)
|
|
result.elem_[ii][jj] += elem_[ii][kk] * matrix.elem_[kk][jj];
|
|
|
|
return result;
|
|
}
|
|
|
|
vector_3 matrix_3::operator * (const vector_3& vector) const
|
|
{
|
|
vector_3 result;
|
|
|
|
for(__int8 ii = 0; ii < 3; ++ii)
|
|
for(__int8 jj = 0; jj < 3; ++jj)
|
|
result[ii] += elem_[ii][jj] * vector[jj];
|
|
|
|
return result;
|
|
}
|
|
|
|
vector_3 operator * (const vector_3& vector, const matrix_3& matrix)
|
|
{
|
|
vector_3 result;
|
|
|
|
for(__int8 ii = 0; ii < 3; ++ii)
|
|
for(__int8 jj = 0; jj < 3; ++jj)
|
|
result[ii] += matrix.elem_[jj][ii] * vector[jj];
|
|
|
|
return result;
|
|
}
|
|
|
|
matrix_3 operator * (double scalar, const matrix_3& matrix)
|
|
{
|
|
matrix_3 result = matrix;
|
|
|
|
for(__int8 ii = 0; ii < 3; ++ii)
|
|
for(__int8 jj = 0; jj < 3; ++jj)
|
|
result.elem_[ii][jj] *= scalar;
|
|
|
|
return result;
|
|
}
|
|
|
|
transform_3::transform_3(double Xc, double Yc, double Zc,
|
|
double Psicd, double Thetacd, double Phicd)
|
|
: core_matrix_(1, 0, 0,
|
|
0, cos(DTOR * Phicd), sin(DTOR * Phicd),
|
|
0, -sin(DTOR * Phicd), cos(DTOR * Phicd)), // Phic matrix
|
|
core_vector_(Xc, Yc, Zc)
|
|
{
|
|
// Rotation by Thetac matrix
|
|
core_matrix_ *= matrix_3(cos(DTOR * Thetacd), 0, -sin(DTOR * Thetacd),
|
|
0, 1, 0,
|
|
sin(DTOR * Thetacd), 0, cos(DTOR * Thetacd));
|
|
// Rotation by Psic matrix
|
|
core_matrix_ *= matrix_3(cos(DTOR * Psicd), sin(DTOR * Psicd), 0,
|
|
-sin(DTOR * Psicd), cos(DTOR * Psicd), 0,
|
|
0, 0, 1);
|
|
}
|
|
|
|
void transform_3::get_ptz_params(double angle, double range, ptz_params& params)
|
|
{
|
|
double theta_t_s = .0; // Assume that the tilt ot the target is 0[deg].
|
|
// Latter we can put as the tilt of the LRF
|
|
|
|
// Transformation to camera system, r_t_c = Target vector in camera system [m]
|
|
vector_3 r_t_c = core_matrix_ * (range * vector_3(cos(DTOR * angle) * cos(theta_t_s),
|
|
sin(DTOR * angle) * cos(theta_t_s),
|
|
-sin(theta_t_s)) - core_vector_);
|
|
|
|
params.pan = static_cast<float> (RTOD * atan2(r_t_c[1], r_t_c[0])); // Pan, in degree
|
|
params.tilt = static_cast<float> (RTOD * atan2(-r_t_c[2], sqrt(r_t_c[0] * r_t_c[0] + r_t_c[1] * r_t_c[1]))); // Tilt, in degree
|
|
params.dist = static_cast<float> (sqrt(r_t_c * r_t_c)); // Range, in meters
|
|
}
|
|
|