Jump to content

need help on arrangement.

- - - - -

  • Please log in to reply
No replies to this topic

#1
HiBye

HiBye

    Newbie

  • Members
  • Pip
  • 2 posts
void __fastcall TFormMain::TimerTimer(TObject *Sender)

{

	float repelX0, repelY0, repelX1, repelY1;

	float dxPrev, dyPrev;

	float dxNext, dyNext;

	eachSegment = 25.0;    shortLines = 0;


	for( int i = 0; i < numPoints; i++ )

	{

		if( i == 0 )

		{

			dxPrev = srcX - x[ i ]; // the force in btw the 2 boxes.

			dyPrev = srcY - y[ i ];

		}

		else

		{

			dxPrev = x[ i - 1 ] - x[ i ]; // the force in btw the 2 boxes.

			dyPrev = y[ i - 1 ] - y[ i ];

		}

		if( i == numPoints - 1 )

		{

			dxNext = dstX - x[ i ];

			dyNext = dstY - y[ i ];

		}

		else

		{

			dxNext = x[ i + 1 ] - x[ i ];

			dyNext = y[ i + 1 ] - y[ i ];

		}

		

		float dx = ( x[ i ] - obsX[ 0 ] );  // the x-axis different btw green

		float dy = ( y[ i ] - obsY[ 0 ] );  // boxes and the obstacle

		float d = sqrt( dx * dx + dy * dy );



 /*			if( d > 50.0 )

			{

			repelX0 = 0.0;

			repelY0 = 0.0;

			}

			else

			{  */

			repelX0 = ( dx / d ) * ( 500.0 / d );

			repelY0 = ( dy / d ) * ( 500.0 / d );  // The force on the Y-axis

//			}


		dx = ( x[ i ] - obsX[ 1 ] );

		dy = ( y[ i ] - obsY[ 1 ] );

		d = sqrt( dx * dx + dy * dy );

/*		if( d > 50.0 )

		{

			repelX1 = 0.0; // if the distance is more than 100.0 , the boxes

			repelY1 = 0.0;  // will not be movin as no force acted on it.

		}

		else

		{    */

			repelX1 = ( dx / d ) * ( 500.0 / d ); // the 500.0 is the force

			repelY1 = ( dy / d ) * ( 500.0 / d ); // that i wan to use

//		}


		float tx = ( dxPrev + dxNext ) + repelX0 + repelX1 ;

		float ty = ( dyPrev + dyNext ) + repelY0 + repelY1 ;


		x[ i ] += 0.5 * tx;    // move in the direction of the force tx.

		y[ i ] += 0.5 * ty;

	}


		Calculation();    // calculation of the total length.                                                                           		Calculation();

		shortLines = TotalLength / eachSegment;// how many parts.

		numPoints = shortLines - 1; // how many green box.

  /*	 while (numPoints++)

		{


		}

				   */

		PaintBox->Repaint();

}

//---------------------------------------------------------------------------

void TFormMain:: Calculation()

{

	float smallLengthX , smallLengthY, totalsmallLength;

	smallLengthX = 0;   smallLengthY = 0, totalsmallLength = 0;


	float smallLengthXX, smallLengthYY, totalsmallLengthH;

	smallLengthXX = 0;  smallLengthYY = 0, totalsmallLengthH = 0;


	float totaleachLength, totaleachLengthH;

	totaleachLength = 0, totaleachLengthH = 0;


	float eachLengthX, eachLengthY;

	eachLengthX = 0, eachLengthY = 0;

	TotalLength = 0;


	for( int i = 1; i < numPoints; i++)

	{

			eachLengthX = x[ i ] - x[ i - 1 ];

			eachLengthY = y[ i ] - y[ i - 1 ];

			totaleachLength = sqrt( eachLengthX * eachLengthX +

									eachLengthY * eachLengthY);

			totaleachLengthH += totaleachLength;

	}


	  smallLengthX = x[ 0 ] - srcX;

	  smallLengthY = y[ 0 ] - srcY;


	  totalsmallLength = sqrt( smallLengthX * smallLengthX +

									smallLengthY * smallLengthY);


	  smallLengthXX = dstX - x[ numPoints - 1 ];

	  smallLengthYY = dstY - y[ numPoints - 1 ];


	  totalsmallLengthH = sqrt( smallLengthXX * smallLengthXX +

									smallLengthYY * smallLengthYY);


	  TotalLength = totalsmallLength + totalsmallLengthH + totaleachLengthH;


}




the output of the programme is there are two poles spread apart and there are string holding on to the poles.In between them , there are beans attached to the string.the problem i have is , the beans are not equally spread according to a certain length which i define myself. what i should do to make them spread equally ?
Thank you for helping.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users