static bool find_third_point(int num_points, const double (*points)[3], int a, int b, int* p_c)
{
	const double* x1 = points[a];
	const double* x2 = points[b];

	double x2x1[3] = {x2[0] - x1[0], x2[1] - x1[1], x2[2] - x1[2]};
	double ns_x2x1 = norm_squared(x2x1);

	int bi = -1;
	double max_dist = 0.0;
	for (int i = 0;i<num_points;i++)
	{
		if (i == a || i == b)
			continue;

		const double* x0 = points[i];

		double x1x0[3] = {x1[0] - x0[0], x1[1] - x0[1], x1[2] - x0[2]};
		double dot = dot_product(x1x0, x2x1);
		double dist = (norm_squared(x1x0) * ns_x2x1 - dot*dot) / ns_x2x1;

		if (dist > max_dist)
		{
			max_dist = dist;
			bi = i;
		}
	}

	*p_c = bi;
	return max_dist > TOLERANCE;
}
Exemplo n.º 2
0
 /// normalization
 inline __host__ __device__ float normalize() {
     float l = sqrtf(norm_squared());
     float f = 1.f / l;
     x *= f;
     y *= f;
     z *= f;
     return l;
 }
Exemplo n.º 3
0
 /// normalization
 float normalize() {
     float l = sqrtf(norm_squared());
     float f = 1.f / l;
     x *= f;
     y *= f;
     z *= f;
     return l;
 }
Exemplo n.º 4
0
 /// normalization
 inline __host__ __device__ float safe_normalize(const float eps = 1e-10f) {
     float l = sqrtf(norm_squared());
     if(l > eps){
         float f = 1.f / l;
         x *= f;
         y *= f;
         z *= f;
         return l;
     } else {
         x = 1.f;
         y = 0.f;
         z = 0.f;
         return 0.f;
     }
 }
Exemplo n.º 5
0
inline double skew_x( VerdictVector& q1,
                      VerdictVector& q2,
                      VerdictVector& q3,
                      VerdictVector& qw1,
                      VerdictVector& qw2,
                      VerdictVector& qw3 )
{
    double normsq1, normsq2, kappa;
    VerdictVector u1, u2, u3;
    VerdictVector x1, x2, x3;

    inverse(qw1,qw2,qw3,u1,u2,u3);
    product(q1,q2,q3,u1,u2,u3,x1,x2,x3);
    inverse(x1,x2,x3,u1,u2,u3);
    normsq1 = norm_squared(x1,x2,x3);
    normsq2 = norm_squared(u1,u2,u3);
    kappa = sqrt( normsq1 * normsq2 );

    double skew = 0;
    if ( kappa > VERDICT_DBL_MIN )
        skew = 3/kappa;

    return skew;
}
static void calculate_plane_normal(const double (*points)[3], int a, int b, int c, double* plane_normal)
{
	double u[3] = {	points[b][0] - points[a][0],
			points[b][1] - points[a][1],
			points[b][2] - points[a][2]	};

	double v[3] = {	points[c][0] - points[a][0],
			points[c][1] - points[a][1],
			points[c][2] - points[a][2]	};

	cross_product(u, v, plane_normal);
	double norm = sqrt(norm_squared(plane_normal));
	plane_normal[0] /= norm;
	plane_normal[1] /= norm;
	plane_normal[2] /= norm;
}
Exemplo n.º 7
0
void PitchFlockViewer::plot_bend ()
{
  const size_t I = synth().size;
  const size_t X = Rectangle::width();
  const size_t Y = Rectangle::height();

  const float * restrict power = get_power();
  const float * restrict energy = get_energy();
  const float * restrict bend = synth().get_bend();
  float * restrict red = m_bend_image.red;
  float * restrict green = m_bend_image.green;
  float * restrict blue = m_bend_image.blue;

  float energy_gain = m_energy_gain.update(max(get_energy()));
  float power_gain = m_power_gain.update(max(get_power()));
  float bend_variance = norm_squared(synth().get_bend()) / I;
  float bend_gain = m_bend_gain.update(bend_variance);
  float min_freq = min(synth().get_freq());
  float max_freq = max(synth().get_freq());
  float pitch_scale = 1 / log(max_freq / min_freq);

  if (m_image_mutex.try_lock()) {

    for (size_t i = 0; i < I; ++i) {

      float m = energy_gain * energy[i];
      float e = power_gain * power[i];

      float b = atanf(0.5f * bend_gain * bend[i]) / M_PI + 0.5f;
      float p = static_cast<float>(i) / I + pitch_scale * log(1 + bend[i]);

      BilinearInterpolate lin(b * X, X, p * Y, Y);

      lin.imax(red, e);
      lin.imax(green, m);
      lin.imax(blue, 1);
    }

    m_image_mutex.unlock();
  }
}
static int initial_simplex(int num_points, const double (*points)[3], int* initial_vertices)
{
	int min_index[3] = {0};
	int max_index[3] = {0};
	if (!calc_max_extent(num_points, points, min_index, max_index))
		return -1;

	int bi = -1;
	double max_dist = 0.0;
	for (int i = 0;i<3;i++)
	{
		int a = min_index[i], b = max_index[i];
		double delta[3] = {	points[a][0] - points[b][0],
					points[a][1] - points[b][1],
					points[a][2] - points[b][2]	};
		double dist = norm_squared(delta);
		if (dist > max_dist)
		{
			bi = i;
			max_dist = dist;
		}
	}

	//first two points are (a, b)
	int a = min_index[bi], b = max_index[bi], c = -1, d = -1;

	if (!find_third_point(num_points, points, a, b, &c))
		return -2;

	if (!find_fourth_point(num_points, points, a, b, c, &d))
		return -3;

	initial_vertices[0] = a;
	initial_vertices[1] = b;
	initial_vertices[2] = c;
	initial_vertices[3] = d;
	return 0;
}
Exemplo n.º 9
0
 /// norm
 inline __host__ __device__ float norm() const {
     return sqrtf(norm_squared());
 }
Exemplo n.º 10
0
 /// normalization
 inline __host__ __device__ Vec3 normalized() const {
     return (*this) * (1.f/sqrtf(norm_squared()));
 }
Exemplo n.º 11
0
OMEGA_H_INLINE Real norm(Vector<n> v) {
  return sqrt(norm_squared(v));
}
Exemplo n.º 12
0
 /// norm
 float norm() const {
     return sqrtf(norm_squared());
 }
Exemplo n.º 13
0
 /// normalization
 Vec3 normalized() const {
     return (*this) * (1.f/sqrtf(norm_squared()));
 }
Exemplo n.º 14
0
INLINE Real squared_metric_length(Vector<dim> v, DummyIsoMetric) {
  return norm_squared(v);
}
Exemplo n.º 15
0
double norm( const std::vector<double>& v )
{
 return sqrt( norm_squared( v ) ); 
}