Example #1
0
static void filter_2_1(AVFilterContext *ctx)
{
    AudioSurroundContext *s = ctx->priv;
    float *srcl, *srcr, *srclfe;
    int n;

    srcl = (float *)s->input->extended_data[0];
    srcr = (float *)s->input->extended_data[1];
    srclfe = (float *)s->input->extended_data[2];

    for (n = 0; n < s->buf_size; n++) {
        float l_re = srcl[2 * n], r_re = srcr[2 * n];
        float l_im = srcl[2 * n + 1], r_im = srcr[2 * n + 1];
        float lfe_re = srclfe[2 * n], lfe_im = srclfe[2 * n + 1];
        float c_phase = atan2f(l_im + r_im, l_re + r_re);
        float l_mag = hypotf(l_re, l_im);
        float r_mag = hypotf(r_re, r_im);
        float l_phase = atan2f(l_im, l_re);
        float r_phase = atan2f(r_im, r_re);
        float phase_dif = fabsf(l_phase - r_phase);
        float mag_dif = (l_mag - r_mag) / (l_mag + r_mag);
        float mag_total = hypotf(l_mag, r_mag);
        float x, y;

        if (phase_dif > M_PI)
            phase_dif = 2 * M_PI - phase_dif;

        stereo_position(mag_dif, phase_dif, &x, &y);

        s->upmix_2_1(ctx, l_phase, r_phase, c_phase, mag_total, lfe_re, lfe_im, x, y, n);
    }
}
Example #2
0
static float complex
clog_for_large_values(float complex z)
{
	float x, y;
	float ax, ay, t;

	x = crealf(z);
	y = cimagf(z);
	ax = fabsf(x);
	ay = fabsf(y);
	if (ax < ay) {
		t = ax;
		ax = ay;
		ay = t;
	}

	if (ax > FLT_MAX / 2)
		return (CMPLXF(logf(hypotf(x / m_e, y / m_e)) + 1,
		    atan2f(y, x)));

	if (ax > QUARTER_SQRT_MAX || ay < SQRT_MIN)
		return (CMPLXF(logf(hypotf(x, y)), atan2f(y, x)));

	return (CMPLXF(logf(ax * ax + ay * ay) / 2, atan2f(y, x)));
}
Example #3
0
  void propagate_locals(object_planar* instance)
  {
    if(instance->gravity || instance->friction)
    {
      double
        hb4 = instance->hspeed.rval.d,
        vb4 = instance->vspeed.rval.d;
      int sign = (instance->speed > 0) - (instance->speed < 0);
      if (instance->hspeed!=0)
        instance->hspeed.rval.d -= (sign * instance->friction) * cos(instance->direction.rval.d * M_PI/180);
      if ((hb4>0 && instance->hspeed.rval.d<0) || (hb4<0 && instance->hspeed.rval.d>0))
        instance->hspeed.rval.d=0;
        if (instance->vspeed!=0)
        instance->vspeed.rval.d -= (sign * instance->friction) * -sin(instance->direction.rval.d * M_PI/180);
      if ((vb4>0 && instance->vspeed.rval.d<0) || (vb4<0 && instance->vspeed.rval.d>0))
        instance->vspeed.rval.d=0;

      instance->hspeed.rval.d += (instance->gravity) * cos(instance->gravity_direction * M_PI/180);
      instance->vspeed.rval.d += (instance->gravity) *-sin(instance->gravity_direction * M_PI/180);

      if(instance->speed.rval.d<0)
        instance->direction.rval.d = fmod(instance->direction.rval.d + 180, 360),
        instance->speed.    rval.d = -hypotf(instance->hspeed.rval.d, instance->vspeed.rval.d);
      else
        instance->direction.rval.d = fmod(instance->direction.rval.d, 360),
        instance->speed.    rval.d =  hypotf(instance->hspeed.rval.d, instance->vspeed.rval.d);
      if(instance->direction.rval.d < 0)
        instance->direction.rval.d += 360;
    }

    instance->x += instance->hspeed.rval.d;
    instance->y += instance->vspeed.rval.d;
  }
Example #4
0
static void normalize( float v[3] ) {
	float len = hypotf(v[0], hypotf(v[1], v[2]));
	if( len ) {
		v[0] /= len;
		v[1] /= len;
		v[2] /= len;
	}
}
Example #5
0
static inline void
do_hard_work(float x, float y, float *rx, int *B_is_usable, float *B,
    float *sqrt_A2my2, float *new_y)
{
	float R, S, A;
	float Am1, Amy;

	R = hypotf(x, y + 1);
	S = hypotf(x, y - 1);

	A = (R + S) / 2;
	if (A < 1)
		A = 1;

	if (A < A_crossover) {
		if (y == 1 && x < FLT_EPSILON * FLT_EPSILON / 128) {
			*rx = sqrtf(x);
		} else if (x >= FLT_EPSILON * fabsf(y - 1)) {
			Am1 = f(x, 1 + y, R) + f(x, 1 - y, S);
			*rx = log1pf(Am1 + sqrtf(Am1 * (A + 1)));
		} else if (y < 1) {
			*rx = x / sqrtf((1 - y) * (1 + y));
		} else {
			*rx = log1pf((y - 1) + sqrtf((y - 1) * (y + 1)));
		}
	} else {
		*rx = logf(A + sqrtf(A * A - 1));
	}

	*new_y = y;

	if (y < FOUR_SQRT_MIN) {
		*B_is_usable = 0;
		*sqrt_A2my2 = A * (2 / FLT_EPSILON);
		*new_y = y * (2 / FLT_EPSILON);
		return;
	}

	*B = y / A;
	*B_is_usable = 1;

	if (*B > B_crossover) {
		*B_is_usable = 0;
		if (y == 1 && x < FLT_EPSILON / 128) {
			*sqrt_A2my2 = sqrtf(x) * sqrtf((A + y) / 2);
		} else if (x >= FLT_EPSILON * fabsf(y - 1)) {
			Amy = f(x, y + 1, R) + f(x, y - 1, S);
			*sqrt_A2my2 = sqrtf(Amy * (A + y));
		} else if (y > 1) {
			*sqrt_A2my2 = x * (4 / FLT_EPSILON / FLT_EPSILON) * y /
			    sqrtf((y + 1) * (y - 1));
			*new_y = y * (4 / FLT_EPSILON / FLT_EPSILON);
		} else {
			*sqrt_A2my2 = sqrtf((1 - y) * (1 + y));
		}
	}
}
Example #6
0
static void init_wave(int init, 
		      int nx, float dx,
		      int nz, float dz,
		      sf_complex *pp /* [nx] */,
		      float wov, int nw, int iw)
{
    int ix;
    float x,x0,z0,phase,amp;
    
    x0 = nx*dx/3;
    z0 = nz*dz/3;

    switch(init) {
	case 1: /*  planar wave @ 15deg */
	    for (ix=0; ix < nx; ix++) {
		x = (ix+1)*dx - x0;
		phase  = wov*x*sinf(15*SF_PI/180.);
		pp[ix] = cexpf(sf_cmplx(0.,phase));
	    }
	    break;
	case 2: /* expanding spherical wave */
	    for (ix=0; ix < nx; ix++) {
		x = (ix+1)*dx - x0;
		phase  = wov*hypotf(z0,x);
		pp[ix] = cexpf(sf_cmplx(0.,phase));
	    }
	    break;
	case 3: /* point source */
	    for (ix=0; ix < nx; ix++) {
		pp[ix]=sf_cmplx(0.,0.);
	    }
	    pp[nx/3-1] = sf_cmplx(1.,0.);
	    break;
	case 4: /* collapsing spherical wave */
	    for (ix=0; ix < nx; ix++) {
		x = (ix+1)*dx - x0;
		phase  = -wov*hypotf(z0,x);
		pp[ix] = cexpf(sf_cmplx(0.,phase));
	    }
	    break;
	default:
	    sf_error("Unknown init=%d",init);
    }

    amp = (nw-iw+1.0)/nw;
    amp = cosf((1-amp)*(0.5*SF_PI));
    amp *= amp;

    for (ix=0; ix < nx; ix++) {
#ifdef SF_HAS_COMPLEX_H
	pp[ix] *= amp;
#else
	pp[ix] = sf_crmul(pp[ix],amp);
#endif
    }
}
Example #7
0
void gline(float x1, float y1, float x2, float y2, float width, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
	#ifdef	OPENGL
		glColor4f(((float) r) / 255.0, ((float) g) / 255.0, ((float) b) / 255.0, ((float) a) / 255.0);
		//   c1x,c1y
		//  0,0......
		//   c4x,c4y  ........       c2x,c2y
		//                    ........ px,py
		//                       c3x,c3y
		float c1x, c1y, c1l, c2x, c2y, c2l, c3x, c3y, c3l, c4x, c4y, c4l;

		float px = x2 - x1;
		float py = y2 - y1;

		c1x = -py;
		c1y = px;
		c1l = hypotf(c1x, c1y);
		c1x = (c1x * width / c1l / 2.0) + x1;
		c1y = (c1y * width / c1l / 2.0) + y1;

		c2x = -py;
		c2y = px;
		c2l = hypotf(c2x, c2y);
		c2x = (c2x * width / c2l / 2.0) + px + x1;
		c2y = (c2y * width / c2l / 2.0) + py + y1;

		c3x = py;
		c3y = -px;
		c3l = hypotf(c3x, c3y);
		c3x = (c3x * width / c3l / 2.0) + px + x1;
		c3y = (c3y * width / c3l / 2.0) + py + y1;

		c4x = py;
		c4y = -px;
		c4l = hypotf(c4x, c4y);
		c4x = (c4x * width / c4l / 2.0) + x1;
		c4y = (c4y * width / c4l / 2.0) + y1;

		if (width == 4.0)
			printf("LINE: [%3.0f,%3.0f]->[%3.0f,%3.0f]->[%3.0f,%3.0f]->[%3.0f,%3.0f]\n", c1x, c1y, c2x, c2y, c3x, c3y, c4x, c4y);

		glVertex2f(c1x, c1y);
		glVertex2f(c2x, c2y);
		glVertex2f(c3x, c3y);
		glVertex2f(c4x, c4y);
	#else
	thickLineRGBA(Surf_Display,
		(x1 - viewPortL) * zoomFactor,
		(viewPortB - y1) * zoomFactor,
		(x2 - viewPortL) * zoomFactor,
		(viewPortB - y2) * zoomFactor,
		mind(maxd(width * zoomFactor, 1), 2),
		r, g, b, a
		);
	#endif
}
void FX_DreamPrecalc(CinematicBitmap * bi, float amp, float fps) {
	
	float a = DreamAng;
	float a2 = DreamAng2;
	
	Vec2f s;
	s.x = float(bi->m_count.x) * std::cos(glm::radians(0.f));
	s.y = float(bi->m_count.y) * std::cos(glm::radians(0.f));
	
	Vec2i n;
	n.x = (bi->m_count.x + 1) << 1;
	n.y = (bi->m_count.y + 1) << 1;
	
	Vec2f nn = Vec2f(n) + s;
	
	Vec2f o;
	o.x = amp * ((2 * (std::sin(nn.x / 20) + std::sin(nn.x * nn.y / 2000)
	                  + std::sin((nn.x + nn.y) / 100) + std::sin((nn.y - nn.x) / 70) + std::sin((nn.x + 4 * nn.y) / 70)
	                  + 2 * std::sin(hypotf(256 - nn.x, (150 - nn.y / 8)) / 40))));
	o.y = amp * (((std::cos(nn.x / 31) + std::cos(nn.x * nn.y / 1783) +
	              + 2 * std::cos((nn.x + nn.y) / 137) + std::cos((nn.y - nn.x) / 55) + 2 * std::cos((nn.x + 8 * nn.y) / 57)
	              + std::cos(hypotf(384 - nn.x, (274 - nn.y / 9)) / 51))));
	
	float * t = DreamTable;
	n.y = ((bi->m_count.y * bi->grid.m_scale) + 1);
	
	while(n.y) {
		n.x = ((bi->m_count.x * bi->grid.m_scale) + 1);
		while(n.x) {
			s.x = float(bi->m_count.x) * std::cos(glm::radians(a));
			s.y = float(bi->m_count.y) * std::cos(glm::radians(a2));
			a -= 15.f;
			a2 += 8.f;
			
			nn.x = float(n.x) + s.x;
			nn.y = float(n.y) + s.y;
			
			*t++ = (-o.x + amp * ((2 * (std::sin(nn.x / 20) + std::sin(nn.x * nn.y / 2000)
			                                  + std::sin((nn.x + nn.y) / 100) + std::sin((nn.y - nn.x) / 70) + std::sin((nn.x + 4 * nn.y) / 70)
			                                  + 2 * std::sin(hypotf(256 - nn.x, (150 - nn.y / 8)) / 40)))));
			*t++ = (-o.y + amp * (((std::cos(nn.x / 31) + std::cos(nn.x * nn.y / 1783) +
			                              + 2 * std::cos((nn.x + nn.y) / 137) + std::cos((nn.y - nn.x) / 55) + 2 * std::cos((nn.x + 8 * nn.y) / 57)
			                              + std::cos(hypotf(384 - nn.x, (274 - nn.y / 9)) / 51)))));
			
			n.x--;
		}
		n.y--;
	}
	
	DreamAng += 4.f * fps;
	DreamAng2 -= 2.f * fps;
}
void			SegmentedShotStrategy::update(float dt)
{
  prevTime = currentTime;
  currentTime += dt;

  // see if we've moved to another segment
  const int numSegments = segments.size();
  if (segment < numSegments && segments[segment].end <= currentTime) {
    lastSegment = segment;
    while (segment < numSegments && segments[segment].end <= currentTime) {
      if (++segment < numSegments) {
	switch (segments[segment].reason) {
	  case ShotPathSegment::Ricochet: {
	    // play ricochet sound.  ricochet of local player's shots
	    // are important, others are not.
	    const float* pos = segments[segment].ray.getOrigin();
	    playWorldSound(SFX_RICOCHET, pos[0], pos[1], pos[2],
		getPath().getPlayer() == LocalPlayer::getMyTank()->getId());
	    break;
	  }
	  default:
	    // currently no sounds for anything else
	    break;
	}
      }
    }
  }

  // if ran out of segments then expire shot on next update
  if (segment == numSegments) {
    setExpiring();

    if (numSegments > 0) {
	    ShotPathSegment& segment = segments[numSegments - 1];
	    const float* dir = segment.ray.getDirection();
	    const float speed = hypotf(dir[0], hypotf(dir[1], dir[2]));
	    float pos[3];
	    segment.ray.getPoint(segment.end - segment.start - 1.0f / speed, pos);
	    /* NOTE -- comment out to not explode when shot expires */
	    addShotExplosion(pos);
    }
  }

  // otherwise update position and velocity
  else {
    float p[3];
    segments[segment].ray.getPoint(currentTime - segments[segment].start, p);
    setPosition(p);
    setVelocity(segments[segment].ray.getDirection());
  }
}
void			SegmentedShotStrategy::radarRender() const
{
  const float *orig = getPath().getPosition();
  const int length = BZDBCache::linedRadarShots;
  const int size   = BZDBCache::sizedRadarShots;

  float shotTailLength = BZDB.eval(StateDatabase::BZDB_SHOTTAILLENGTH);

  // Display leading lines
  if (length > 0) {
    const float* vel = getPath().getVelocity();
    const float d = 1.0f / hypotf(vel[0], hypotf(vel[1], vel[2]));
    float dir[3];
    dir[0] = vel[0] * d * shotTailLength * length;
    dir[1] = vel[1] * d * shotTailLength * length;
    dir[2] = vel[2] * d * shotTailLength * length;
    glBegin(GL_LINES);
    glVertex2fv(orig);
    glVertex2f(orig[0] - dir[0], orig[1] - dir[1]);
    glEnd();

    // draw a "bright" bullet tip
    if (size > 0) {
      glColor3f(0.75, 0.75, 0.75);
      glPointSize((float)size);
      glBegin(GL_POINTS);
      glVertex2f(orig[0], orig[1]);
      glEnd();
      glPointSize(1.0f);
    }
  } else {
    if (size > 0) {
      // draw a sized bullet
      glPointSize((float)size);
      glBegin(GL_POINTS);
      glVertex2fv(orig);
      glEnd();
      glPointSize(1.0f);

    } else {
      // draw the tiny little bullet
      glBegin(GL_POINTS);
      glVertex2fv(orig);
      glEnd();
    }
  }

}
Example #11
0
//asq: transformed to "new"-style declaration
float
cabsf(float complex z)
//	float complex z;
{

	return hypotf(crealf(z), cimagf(z));
}
Example #12
0
FastSymmetryDetector::FastSymmetryDetector( const Size image_size, const Size hough_size, const int rot_resolution ) {
    this->imageSize     = image_size;
    this->center        = Point2f( imageSize.width - 1.0, imageSize.height - 1.0 ) * 0.5;
    this->diagonal      = hypotf( imageSize.width, imageSize.height );
    this->rhoDivision   = diagonal;
    this->rhoMax        = hough_size.width;
    this->thetaMax      = hough_size.height;
    
    rotMatrices.resize( thetaMax, Mat(2, 2, CV_32FC1) );
    
    float thetaIncDeg = 180.0f / thetaMax;
    float half_theta_max = thetaMax * 0.5f;
    
    /* Pre calculate rotation matrices from -90 deg to 90 deg (actually to 89 deg) */
    for( int t = 0; t < thetaMax; t++ ){
        double angle = thetaIncDeg * ( t - half_theta_max );
        Mat rotation = getRotationMatrix2D( Point2f(0.0, 0.0), angle, 1.0);
        rotation.convertTo( rotation, CV_32FC1 );
        
        rotMatrices[t] = Mat( rotation, Rect(0, 0, 2, 2) );
        rotMatrices[t].row(0) *= 0.5;
    }
    
    accum       = Mat::zeros( thetaMax + 2, rhoMax, CV_32FC1 );
    rotEdges    = Mat::zeros( rhoDivision, diagonal, CV_32FC1 );
    reRows.resize( rhoDivision );
}
Example #13
0
/// Convert a direction vector to latlong st coordinates
///
inline void
vector_to_latlong(const Imath::V3f& R, bool y_is_up, float& s, float& t)
{
    if (y_is_up) {
        s = atan2f(-R[0], R[2]) / (2.0f * (float)M_PI) + 0.5f;
        t = 0.5f - atan2f(R[1], hypotf(R[2], -R[0])) / (float)M_PI;
    } else {
        s = atan2f(R[1], R[0]) / (2.0f * (float)M_PI) + 0.5f;
        t = 0.5f - atan2f(R[2], hypotf(R[0], R[1])) / (float)M_PI;
    }
    // learned from experience, beware NaNs
    if (isnan(s))
        s = 0.0f;
    if (isnan(t))
        t = 0.0f;
}
Example #14
0
inline void draw_agent_connectivity( void )
{
    int i, j;

    glColor3fv( agent_color_conn );

    for ( i = 0; i < params.agent_number; ++i )
    {
        Agent *a1 = agents[i];
        Vector2f a1_pos = a1->position;

        for ( j = i; j < params.agent_number; ++j )
        {
            Agent *a2 = agents[j];
            Vector2f a2_pos = a2->position;

            float distance = hypotf( a1_pos.x - a2_pos.x, a1_pos.y - a2_pos.y );

            if ( distance <= params.range_coefficient * params.R )
            {
                glBegin( GL_LINES );
                    if ( a1_pos.x < 0.0f ) { glVertex2f( 0.0f, a1_pos.y ); }
                    else if ( a1_pos.y < 0.0f ) { glVertex2f( a1_pos.x, 0.0f ); }
                    else if ( a1_pos.x < 0.0f && a1_pos.y < 0.0f ) { glVertex2f( 0.0f, 0.0f ); }
                    else { glVertex2f( a1_pos.x, a1_pos.y ); }

                    if ( a2_pos.x < 0.0f ) { glVertex2f( 0.0f, a2_pos.y ); }
                    else if ( a2_pos.y < 0.0f ) { glVertex2f( a2_pos.x, 0.0f ); }
                    else if ( a2_pos.x < 0.0f && a2_pos.y < 0.0f ) { glVertex2f( 0.0f, 0.0f ); }
                    else { glVertex2f( a2_pos.x, a2_pos.y ); }
                glEnd();
            }
        }
    }
}
Example #15
0
void mk_minimum_displacement(struct points *p, float *rx, float *ry)
{
        struct points *n = p;
        struct points *tmp = p;
        float smallest_v = FLT_MAX;
        float v = 0;
        float x = 0, y = 0;
        int i = 0;

        while(tmp != NULL) {
                i++;
                if (tmp->next == NULL) {
                        if (tmp == p) {
                                break;
                        }
                        n = p;
                } else {
                        n = tmp->next;
                }

                get_point_on_segment(tmp, n, &x, &y);
                v = hypotf(x, y);

                if (smallest_v > v) {
                        smallest_v = v;
                        *rx = x;
                        *ry = y;
                }

                tmp = tmp->next;
        }
}
Example #16
0
int main(int argc, char* argv[])
{
    int i, id, dim, n[SF_MAX_DIM], nd;
    kiss_fft_cpx *din;
    float *dout;
    sf_file fin, fout;

    sf_init(argc,argv);
    fin = sf_input("in");
    fout = sf_output("out");

    if (SF_COMPLEX != sf_gettype(fin)) sf_error("Need complex input");

    dim = sf_filedims (fin,n);
    nd = 1;

    for (i=0; i < dim; i++) nd *= n[i];

    din = (kiss_fft_cpx*) sf_complexalloc(nd);
    dout = sf_floatalloc(nd);

    sf_floatread((float*)din,nd*2,fin);

    for (id=0; id < nd; id++) {
	dout[id] = hypotf(din[id].r,din[id].i);
    }

    sf_settype(fout, SF_FLOAT);
    sf_setform(fout, SF_NATIVE);

    sf_floatwrite(dout,nd,fout);

    exit(0);
}
Example #17
0
static inline void
FindInflectionApproximationRange(BezierControlPoints aControlPoints,
                                 Float *aMin, Float *aMax, Float aT,
                                 Float aTolerance)
{
    SplitBezier(aControlPoints, nullptr, &aControlPoints, aT);

    Point cp21 = aControlPoints.mCP2 - aControlPoints.mCP1;
    Point cp41 = aControlPoints.mCP4 - aControlPoints.mCP1;

    if (cp21.x == 0 && cp21.y == 0) {
      // In this case s3 becomes lim[n->0] (cp41.x * n) / n - (cp41.y * n) / n = cp41.x - cp41.y.
      *aMin = aT - CubicRoot(double(aTolerance / (cp41.x - cp41.y)));
      *aMax = aT + CubicRoot(aTolerance / (cp41.x - cp41.y));
      return;
    }

    Float s3 = (cp41.x * cp21.y - cp41.y * cp21.x) / hypotf(cp21.x, cp21.y);

    if (s3 == 0) {
      // This means within the precision we have it can be approximated
      // infinitely by a linear segment. Deal with this by specifying the
      // approximation range as extending beyond the entire curve.
      *aMin = -1.0f;
      *aMax = 2.0f;
      return;
    }

    Float tf = CubicRoot(abs(aTolerance / s3));

    *aMin = aT - tf * (1 - aT);
    *aMax = aT + tf * (1 - aT);
}
Example #18
0
static void
FlattenBezierCurveSegment(const BezierControlPoints &aControlPoints,
                          PathSink *aSink,
                          Float aTolerance)
{
  /* The algorithm implemented here is based on:
   * http://cis.usouthal.edu/~hain/general/Publications/Bezier/Bezier%20Offset%20Curves.pdf
   *
   * The basic premise is that for a small t the third order term in the
   * equation of a cubic bezier curve is insignificantly small. This can
   * then be approximated by a quadratic equation for which the maximum
   * difference from a linear approximation can be much more easily determined.
   */
  BezierControlPoints currentCP = aControlPoints;

  Float t = 0;
  while (t < 1.0f) {
    Point cp21 = currentCP.mCP2 - currentCP.mCP3;
    Point cp31 = currentCP.mCP3 - currentCP.mCP1;

    Float s3 = (cp31.x * cp21.y - cp31.y * cp21.x) / hypotf(cp21.x, cp21.y);

    t = 2 * Float(sqrt(aTolerance / (3. * abs(s3))));

    if (t >= 1.0f) {
      aSink->LineTo(aControlPoints.mCP4);
      break;
    }

    Point prevCP2, prevCP3, nextCP1, nextCP2, nextCP3;
    SplitBezier(currentCP, nullptr, &currentCP, t);

    aSink->LineTo(currentCP.mCP1);
  }
}
Example #19
0
fixed_t FixedHypot(fixed_t x, fixed_t y)
{
#ifdef HAVE_HYPOT
	const float fx = FIXED_TO_FLOAT(x);
	const float fy = FIXED_TO_FLOAT(y);
	float fz;
#ifdef HAVE_HYPOTF
	fz = hypotf(fx, fy);
#else
	fz = (float)hypot(fx, fy);
#endif
	return FLOAT_TO_FIXED(fz);
#else // !HAVE_HYPOT
	fixed_t ax, yx, yx2, yx1;
	if (abs(y) > abs(x)) // |y|>|x|
	{
		ax = abs(y); // |y| => ax
		yx = FixedDiv(x, y); // (x/y)
	}
	else // |x|>|y|
	{
		ax = abs(x); // |x| => ax
		yx = FixedDiv(y, x); // (x/y)
	}
	yx2 = FixedMul(yx, yx); // (x/y)^2
	yx1 = FixedSqrt(1+FRACUNIT + yx2); // (1 + (x/y)^2)^1/2
	return FixedMul(ax, yx1); // |x|*((1 + (x/y)^2)^1/2)
#endif
}
Example #20
0
int main() {
	int n, i;
	float r, x, y, x1, y1, x2, y2, s;
	scanf("%d%f%f%f", &n, &r, &x, &y);
	x1 = x2 = x;
	y1 = y2 = y;
	s = 0;
	for (i = 1; i < n; i++) {
		scanf("%f%f", &x2, &y2);
		s += hypotf(x1 - x2, y1 - y2);
		x1 = x2;
		y1 = y2;
	}
	s += hypotf(x2 - x, y2 - y) + 2 * acos(-1) * r;
	printf("%.2f\n", s);
}
Example #21
0
void create_spherical_texture(int size, GLuint& tex)
{
	struct elem {
		unsigned char l;
		unsigned char a;
	};

	elem* buffer = (elem *) malloc(size * size * sizeof(elem));
	float r = (float)size / 2.0;

	for(int i = 0; i < size; ++i)
	{
		for(int j = 0; j < size; ++j)
		{
			float d = hypotf(i - r, j - r);
			buffer[(i * size) + j].l = 255u;
			buffer[(i * size) + j].a = d > r ? 0u : (unsigned char)nearbyint(sqrtf(r*r - d*d) / r * 255.0);
		}
	}

	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, size, size, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, (GLvoid*)buffer);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glBindTexture(GL_TEXTURE_2D, 0);

	free(buffer);
}
void
compute_gradient(float **src, int w, int h, float **g_mag, float **g_ang)
{
	// Sobel mask values
	const float mx0[] = {-0.25f, 0.f, 0.25f};
	const float mx1[] = {-0.5f , 0.f, 0.5f };
	const float mx2[] = {-0.25f, 0.f, 0.25f};
	const float *mx[] = {mx0, mx1, mx2};
	const float my0[] = {-0.25f,-0.5f,-0.25f};
	const float my1[] = { 0.f  , 0.f , 0.f  };
	const float my2[] = { 0.25f, 0.5f, 0.25f};
	const float *my[] = {my0, my1, my2};

	int y, x, i, j, r, c;
#pragma omp parallel for private(x)
	for (y = 0; y < h; y++)
	#pragma omp parallel for private(i, j, r, c)
	for (x = 0; x < w; x++)
	{
		float gx = 0.f, gy = 0.f;
		for (i = 0; i < 3; i++)
		for (j = 0; j < 3; j++)
		{
			r = y+i-1; if(r<0)r=0; else if(r>=h)r=h-1;
			c = x+j-1; if(c<0)c=0; else if(c>=w)c=w-1;
			
			gx += src[r][c] * mx[i][j];
			gy += src[r][c] * my[i][j];
		}
		g_mag[y][x] = hypotf(gy, gx);
		g_ang[y][x] = atan2f(gy, gx);
	}
}
Example #23
0
float complex 
catanf (float complex Z)
{
  float complex Res;
  float complex Tmp;
  float x = __real__ Z;
  float y = __imag__ Z;

  if ( x == 0.0f && (1.0f - fabsf (y)) == 0.0f)
    {
      errno = ERANGE;
      __real__ Res = HUGE_VALF;
      __imag__ Res = HUGE_VALF;
    }
   else if (isinf (hypotf (x, y)))
   {
     __real__ Res = (x > 0 ? M_PI_2 : -M_PI_2);
     __imag__ Res = 0.0f;
   }
  else
    {
      __real__ Tmp = - x; 
      __imag__ Tmp = 1.0f - y;

      __real__ Res = x; 
      __imag__ Res = y + 1.0f;

      Tmp = clogf (Res/Tmp);	
      __real__ Res  = - 0.5f * __imag__ Tmp;
      __imag__ Res =  0.5f * __real__ Tmp;
    }

   return Res; 
}
Example #24
0
void test_hypot()
{
    static_assert((std::is_same<decltype(hypot((double)0, (double)0)), double>::value), "");
    static_assert((std::is_same<decltype(hypotf(0,0)), float>::value), "");
    static_assert((std::is_same<decltype(hypotl(0,0)), long double>::value), "");
    assert(hypot(3,4) == 5);
}
Example #25
0
void Analyzer::fftabs(float *re, float *im, int start, int end, float& maxvalue, int& maxindex, int fftsize)
{
	//float scaling_0dBu = sqrt((6.303352392838346e-25 * 65536.0 * 65536.0) / (2.11592368524*2.11592368524)) / float(fftsize);
	float scaling_0dBu = 2.43089234e-8 / float(fftsize);
	//float scaling_0dBu = 1.20438607134e-8 / float(fftsize);
	float maxv = 0;
	int maxi = 0;

	start = max(1, start);
	start = min(start, fftsize/2);
	end = max(1, end);
	end = min(end, fftsize/2);

	for (int i = start; i < end; ) {
		int n = min(end - i, 256);

		for (; n--; i++) {
			float a = hypotf(re[i], im[i]) * scaling_0dBu;
			re[i] = a;
			if (a > maxv) {
				maxv = a;
				maxi = i;
			}
		}
	}

	maxvalue = maxv;
	maxindex = maxi;
}
Example #26
0
float get_initial_range_guess(float bearing, float heading, uint8_t power){
	int8_t bestS = (6-((int8_t)ceilf((3.0*bearing)/M_PI)))%6;
	float alpha = pretty_angle(bearing - basis_angle[bestS]);				  //alpha using infinite approximation
	int8_t bestE = (6-((int8_t)ceilf((3.0*(bearing-heading-M_PI))/M_PI)))%6;					
	float  beta = pretty_angle(bearing - heading - basis_angle[bestE] - M_PI); //beta using infinite approximation	
	
	//printf("(alpha: %f, sensor %u)\r\n", rad_to_deg(alpha), bestS); 	
	if((alpha > M_PI_2) || (alpha < -M_PI_2)){
		printf("ERROR: alpha out of range (alpha: %f, sensor %u)\r\n", rad_to_deg(alpha), bestS); 
		return 0;
	}
	if((beta > M_PI_2)  || (beta < -M_PI_2)){
		printf("ERROR: beta out of range (beta: %f, emitter %u)\r\n",  beta, bestE); 
		return 0;
	}
	//printf("(beta: %f, emitter %u)\r\n",  rad_to_deg(beta), bestE); 	
	// expected contribution (using infinite distance approximation)
	float amplitude;
	float exp_con = sensor_model(alpha)*emitter_model(beta);
	
	if(exp_con > 0)	amplitude = brightMeas[bestE][bestS]/exp_con;	
	else{
		printf("ERROR: exp_con (%f) is negative (or zero)!\r\n", exp_con); 
		return 0;
	}
	//printf("amp_for_inv: %f\t",amplitude);
	float rMagEst = inverse_amplitude_model(amplitude, power);
	
	float RX = rMagEst*cos(bearing)+DROPLET_RADIUS*(bearingBasis[bestS][0]-headingBasis[bestE][0]);
	float RY = rMagEst*sin(bearing)+DROPLET_RADIUS*(bearingBasis[bestS][1]-headingBasis[bestE][1]);
	
	float rangeEst = hypotf(RX,RY);
	
	return rangeEst;
}
Example #27
0
__complex__ float
clog10f (__complex__ float x)
{
  __complex__ float result;

  if (x == 0.0)
    {
      /* Real and imaginary part are 0.0.  */
      __imag__ result = signbit (__real__ x) ? M_PI : 0.0;
      __imag__ result = copysignf (__imag__ result, __imag__ x);
      /* Yes, the following line raises an exception.  */
      __real__ result = -1.0 / fabsf (__real__ x);
    }
  else if (__real__ x == __real__ x && __imag__ x == __imag__ x)
    {
      /* Neither real nor imaginary part is NaN.  */
      __real__ result = log10f (hypotf (__real__ x, __imag__ x));
      __imag__ result = atan2f (__imag__ x, __real__ x);
    }
  else
    {
      __imag__ result = NAN;
      if (INFINITEF_P (__real__ x) || INFINITEF_P (__imag__ x))
	/* Real or imaginary part is infinite.  */
	__real__ result = HUGE_VALF;
      else
	__real__ result = NAN;
    }

  return result;
}
Example #28
0
static void arrow(float x1, float y1, float x2, float y2)
{
    float dx, dy, r, backx, backy, perpx, perpy, tipx, tipy;
    dx = x2 - x1;
    dy = y2 - y1;
    r = hypotf(dx,dy);
    if ( r < .5)  r = .5;

    backx = -.15 * dx / r;
    backy = -.15 * dy / r;
    perpx =  .05 * dy / r;
    perpy = -.05 * dx / r;
    vp_umove( x1, y1 );         
    vp_udraw( x2, y2 );

    tipx = x2 + backx + perpx;
    tipy = y2 + backy + perpy;
    vp_umove( x2, y2 );         
    vp_udraw( tipx, tipy);

    tipx = x2 + backx - perpx;
    tipy = y2 + backy - perpy;
    vp_umove( x2, y2 );         
    vp_udraw( tipx, tipy);
}
Example #29
0
static TACommandVerdict hypotf_cmd(TAThread thread,TAInputStream stream)
{
    float x, y, res;

    // Prepare

    x = readFloat(&stream);
    y = readFloat(&stream);
    errno = 0;
    
    START_TARGET_OPERATION(thread);
    
    // Execute

    res = hypotf(x, y);
    
    END_TARGET_OPERATION(thread);
    
    // Response
    
    writeFloat(thread, res);
    writeInt(thread, errno);

    sendResponse(thread);
    return taDefaultVerdict;
}
Example #30
0
RealisticCamera::RealisticCamera(const AnimatedTransform &cam2world,
				 float hither, float yon, 
				 float sopen, float sclose, 
				 float filmdistance, float aperture_diameter, string specfile, 
				 float filmdiag, Film *f)
	: Camera(cam2world, sopen, sclose, f) // pbrt-v2 doesnot specify hither and yon
{
	// YOUR CODE HERE -- build and store datastructures representing the given lens
	// and film placement.

	this->hither = hither, this->yon = yon, this->aperture_diameter = aperture_diameter;
	this->filmdistance = filmdistance, this->filmdiag = filmdiag;
	
	// read lens spec file
	this->distToBack = ReadSpecFile(specfile);

	// compute transform: raster to camera, film to camera
	float diag = hypotf(f->xResolution, f->yResolution);
	float scale = filmdiag / diag;
	float X = scale * f->xResolution * 0.5f;
	float Y = scale * f->yResolution * 0.5f;
	RasterToCamera = Translate(Vector(0.f, 0.f, -(this->filmdistance + this->distToBack))) * 
					 Translate(Vector(X, -Y, 0.f)) *
					 Scale(-scale, scale, 1);
}