예제 #1
0
//---------------------------------------------------------
double CSG_Vector::Get_Angle(const CSG_Vector &Vector) const
{
	if( Get_N() > Vector.Get_N() )
	{
		return( Vector.Get_Angle(*this) );
	}

	int		i;
	double	A, B, z, *Z	= Get_Data();

	if( (A = Get_Length()) > 0.0 && (B = Vector.Get_Length()) > 0.0 )
	{
		for(i=0, z=0.0; i<Get_N(); i++)
		{
			z	+= Vector[i] * Z[i];
		}

		for(i=Get_N(); i<Vector.Get_N(); i++)
		{
			z	+= Vector[i];
		}

		return( acos(z / (A * B)) );
	}

	return( 0.0 );
}
예제 #2
0
/**
  * Sets the number of rows to nRows. Values will be preserved.
  * Returns true if successful.
*/
bool CSG_Vector::Set_Rows(int nRows)
{
	if( nRows > Get_N() )
	{
		return( Add_Rows(nRows - Get_N()) );
	}

	if( nRows < Get_N() )
	{
		return( Del_Rows(Get_N() - nRows) );
	}

	return( true );
}
예제 #3
0
//---------------------------------------------------------
double CSG_Vector::Multiply_Scalar(const CSG_Vector &Vector) const
{
	double	z	= 0.0;

	if( Get_N() == Vector.Get_N() )
	{
		for(int i=0; i<Get_N(); i++)
		{
			z	+= Get_Data()[i] * Vector[i];
		}
	}

	return( z );
}
예제 #4
0
/**
  * Deletes last nRows rows. Sets size to zero if nRows is greater
  * than current number of rows
  * Returns true if successful.
*/
bool CSG_Vector::Del_Rows(int nRows)
{
	if( nRows <= 0 )
	{
		return( true );
	}

	if( nRows >= Get_N() )
	{
		return( Destroy() );
	}

	return( m_Array.Set_Array(Get_N() - nRows) );
}
예제 #5
0
//---------------------------------------------------------
bool CSG_Vector::Add_Rows(int nRows)
{
	if( nRows > 0 && m_Array.Set_Array(Get_N() + nRows) )
	{
		for(int i=Get_N()-nRows; i<Get_N(); i++)
		{
			Get_Data()[i]	= 0.0;
		}

		return( true );
	}

	return( false );
}
예제 #6
0
//---------------------------------------------------------
bool CSG_Vector::Subtract(const CSG_Vector &Vector)
{
	if( Get_N() == Vector.Get_N() && Get_N() > 0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	-= Vector.Get_Data()[i];
		}

		return( true );
	}

	return( false );
}
예제 #7
0
//---------------------------------------------------------
bool CSG_Vector::Multiply(double Scalar)
{
	if( Get_N() > 0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	*= Scalar;
		}

		return( true );
	}

	return( false );
}
예제 #8
0
//---------------------------------------------------------
bool CSG_Vector::Multiply(const CSG_Vector &Vector)
{
	if( Get_N() == Vector.Get_N() && Get_N() == 3 )
	{
		CSG_Vector	v(*this);

		Get_Data()[0]	= v[1] * Vector[2] - v[2] * Vector[1];
		Get_Data()[1]	= v[2] * Vector[0] - v[0] * Vector[2];
		Get_Data()[2]	= v[0] * Vector[1] - v[1] * Vector[0];

		return( true );
	}

	return( false );
}
예제 #9
0
int Get_P (double* result)
{
	int ret = 0;
	double val = 0;

	switch (*CUR)
	{
		case '+':
			CUR++;
			break;

		case '-':
			CUR++;
			ret = Get_P (&val);
			val *= -1;
			break;

		case '(':
			CUR++;
			ret = Get_E (&val);
			if (*CUR == ')') CUR++;
			else return ERR_CLOSE_BRACKET;
			break;

		default:
			ret = Get_N (&val);
			break;
	}

	*result = val;

return HAPPY;
}
예제 #10
0
//---------------------------------------------------------
double CSG_Vector::Get_Length(void) const
{
	if( Get_N() > 0 )
	{
		double	z	= 0.0, *Z	= Get_Data();

		for(int i=0; i<Get_N(); i++)
		{
			z	+= Z[i] * Z[i];
		}

		return( sqrt(z) );
	}

	return( 0.0 );
}
예제 #11
0
//---------------------------------------------------------
bool CSG_Vector::is_Equal(const CSG_Vector &Vector) const
{
	if( Get_N() == Vector.Get_N() )
	{
		for(int i=0; i<Get_N(); i++)
		{
			if( Get_Data(i) != Vector.Get_Data(i) )
			{
				return( false );
			}
		}

		return( true );
	}

	return( false );
}
예제 #12
0
//---------------------------------------------------------
bool CSG_Vector::Add_Row(double Value)
{
	if( m_Array.Inc_Array() )
	{
		Get_Data()[Get_N() - 1]	= Value;

		return( true );
	}

	return( false );
}
예제 #13
0
//---------------------------------------------------------
CSG_String CSG_Vector::asString(int Width, int Precision, bool bScientific)	const
{
	CSG_String	s;

	for(int i=0; i<Get_N(); i++)
	{
		s	+= SG_Get_Double_asString(Get_Data(i), Width, Precision, bScientific) + "\n";
	}

	return( s );
}
예제 #14
0
//---------------------------------------------------------
bool CSG_Vector::Assign(const CSG_Vector &Vector)
{
	if( Create(Vector.Get_N()) )
	{
		memcpy(Get_Data(), Vector.Get_Data(), Get_N() * sizeof(double));

		return( true );
	}

	return( false );
}
예제 #15
0
//---------------------------------------------------------
bool CSG_Vector::Set_Unity(void)
{
	double	Length;

	if( (Length = Get_Length()) > 0.0 )
	{
		for(int i=0; i<Get_N(); i++)
		{
			Get_Data()[i]	/= Length;
		}

		return( true );
	}

	return( false );
}
예제 #16
0
double Get_P ()
{
    if (*EXPR_PTR == '(')
    {
        EXPR_PTR++;
        double val1 = Get_E ();

        if (*EXPR_PTR != ')')
            syntax_error ();

        EXPR_PTR++;

        return val1;
    }

    else
        return Get_N ();
}
예제 #17
0
int Get_P (node* tree)
{
	int ret = 0;
	int err_index = 0;
	ASSERT_TREE_OK (tree);

	int sign = 1;
	while ((*CUR) -> op == MATH_OP_ADD || (*CUR) -> op == MATH_OP_SUB)
	{
		if ((*CUR) -> op == MATH_OP_SUB) sign *= -1;
		CUR++;
	}

	if (sign == -1)
	{
		tree -> type = MATH_OP;
		tree -> op   = MATH_OP_MUL;
		tree -> left -> type = NUMBER;
		tree -> left -> num  = -1;

		Tree_Add_Right (tree, Node_NEW());
		ret = Get_E (tree -> right);
		if (ret != HAPPY) if (ret == 0)  return ret;

		if (tree -> right -> type == 0) return ERR_GET_P_LONELY_SIGN;
		
		ASSERT_TREE_OK (tree);
		return HAPPY;
	}

	if ((*CUR) -> op == SEP_OPEN_BRACKET)
	{
		CUR++;
		ret = Get_E (tree);
		if (ret != HAPPY) if (ret == 0)  return ret;
		if ((*CUR) -> op != SEP_CLOSE_BRACKET) return ERR_GET_P_CLOSE_BRACKET;
		CUR++;

		ASSERT_TREE_OK (tree);
		return HAPPY;
	}


	if ((*CUR) -> type == ID)
	{
		if ((*(CUR + 1)) -> op == SEP_OPEN_BRACKET) Get_F (tree);
		else Get_V (tree);

		ASSERT_TREE_OK (tree);
		return HAPPY;
	}

	if ((*CUR) -> type == NUMBER)
	{
		ret = Get_N (tree);

		ASSERT_TREE_OK (tree);
		return HAPPY;
	}

	ASSERT_TREE_OK (tree);
return HAPPY;
}
예제 #18
0
//---------------------------------------------------------
bool CSG_Vector::Set_Zero(void)
{
	return( Create(Get_N()) );
}