f3e15b8c8d
- aggiunti file della libreria e progetto visual studio.
172 lines
4.2 KiB
C
172 lines
4.2 KiB
C
/*****************************************************************************/
|
|
/* */
|
|
/* Copyright (C) 2010-2023 M. Held, S. Huber */
|
|
/* */
|
|
/* This code is not in the public domain. All rights reserved! Please make */
|
|
/* sure to read the full copyright statement contained in "README.txt" or in */
|
|
/* the "main" file of this code, such as "main.cc". */
|
|
/* */
|
|
/*****************************************************************************/
|
|
/* */
|
|
/* Written by: Stefan Huber */
|
|
/* Modified: Martin Held */
|
|
/* */
|
|
/* E-Mail: held@cs.sbg.ac.at */
|
|
/* Fax Mail: (+43 662) 8044-611 */
|
|
/* Voice Mail: (+43 662) 8044-6304 */
|
|
/* Snail Mail: Martin Held */
|
|
/* FB Informatik */
|
|
/* Universitaet Salzburg */
|
|
/* A-5020 Salzburg, Austria */
|
|
/* */
|
|
/*****************************************************************************/
|
|
|
|
|
|
#ifndef VRONI_COORD_H
|
|
#define VRONI_COORD_H
|
|
|
|
|
|
#ifndef DOUBLE_OVERRIDE
|
|
#include <math.h>
|
|
#endif
|
|
|
|
#include "fpkernel.h"
|
|
|
|
/** Defines a vector in the plane */
|
|
struct coord {
|
|
double x;
|
|
double y;
|
|
inline coord(double_arg x, double_arg y) : x(x), y(y) {}
|
|
//Ensure construction doesn't implicitly initialize elements - done explicitly later anyway
|
|
inline coord() {}
|
|
};
|
|
|
|
struct coord3D {
|
|
double x;
|
|
double y;
|
|
double z;
|
|
inline coord3D(double_arg x, double_arg y, double_arg z) : x(x), y(y), z(z) {}
|
|
//Ensure construction doesn't implicitly initialize elements - done explicitly later anyway
|
|
inline coord3D() {}
|
|
};
|
|
|
|
|
|
|
|
/** Computes determinant of 3x3 matrix given by homogeneous coordinates
|
|
* of the three column vectors u, v and w. */
|
|
inline static double VecDet(coord u, coord v, coord w)
|
|
{
|
|
return (((u).x - (v).x) * ((v).y - (w).y) + ((v).y - (u).y) * ((v).x - (w).x));
|
|
}
|
|
|
|
|
|
/** Computes standard inner-product of vectors u and v */
|
|
inline static double VecDotProd(coord u, coord v)
|
|
{
|
|
return (((u).x * (v).x) + ((u).y * (v).y));
|
|
}
|
|
|
|
|
|
/** Adds two vectors */
|
|
inline static coord VecAdd(coord p, coord q)
|
|
{
|
|
coord r;
|
|
r.x = p.x + q.x;
|
|
r.y = p.y + q.y;
|
|
return r;
|
|
}
|
|
|
|
/** Subtracs two vectors */
|
|
inline static coord VecSub(coord p, coord q)
|
|
{
|
|
coord r;
|
|
r.x = p.x - q.x;
|
|
r.y = p.y - q.y;
|
|
return r;
|
|
}
|
|
|
|
|
|
/** Multiply vector with scalar */
|
|
inline static coord VecMult(double_arg scalar, const coord & u)
|
|
{
|
|
coord r;
|
|
r.x = scalar * u.x;
|
|
r.y = scalar * u.y;
|
|
return r;
|
|
}
|
|
|
|
|
|
/** Divide vector by scalar */
|
|
inline static coord VecDiv(double_arg scalar, const coord & u)
|
|
{
|
|
return VecMult(1.0/scalar, u);
|
|
}
|
|
|
|
|
|
/** Get vector -p of p */
|
|
inline static coord VecInv(coord p)
|
|
{
|
|
coord q;
|
|
q.x = -p.x;
|
|
q.y = -p.y;
|
|
return q;
|
|
}
|
|
|
|
|
|
/** Squared vector length */
|
|
inline static double VecLenSq(coord p)
|
|
{
|
|
return (p.x*p.x + p.y*p.y);
|
|
}
|
|
|
|
|
|
/** Vector length */
|
|
inline static double VecLen(coord p)
|
|
{
|
|
return sqrt(VecLenSq(p));
|
|
}
|
|
|
|
/** Normalize vector */
|
|
inline static coord VecNorm(coord p)
|
|
{
|
|
return VecDiv(VecLen(p), p);
|
|
}
|
|
|
|
|
|
/** Get counter clock-wise 90 degree rotation */
|
|
inline static coord VecCCW(coord p)
|
|
{
|
|
coord q;
|
|
q.x = -p.y;
|
|
q.y = p.x;
|
|
return q;
|
|
}
|
|
|
|
|
|
/** Get clock-wise 90 degree rotation */
|
|
inline static coord VecCW(coord p)
|
|
{
|
|
coord q;
|
|
q.x = p.y;
|
|
q.y = -p.x;
|
|
return q;
|
|
}
|
|
|
|
|
|
|
|
/** Make vector by its coordinates */
|
|
inline static coord MakeVec(double_arg x, double_arg y)
|
|
{
|
|
coord p;
|
|
p.x = x;
|
|
p.y = y;
|
|
return p;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|