

Thank you!
I am training for the next ACM ICPC Regionals.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.





Hello,
I'm putting together a Silverlight 2 demo application. It is going to be a simple 2D tank game where you can use the arrow keys to rotate and move the tank. The tank can point in any direction (360 possible directions, right?). I've written the code to rotate the tank, but I'm not sure where to begin regarding moving the tank. How can I take the angle of the tank (say, 156 degrees for example) and use that to determine the next x,y position of the tank when it moves forward?
I'm sure there must be a simple equation for this, but I don't know what it would be called or even how to google this problem.
Any ideas?
Thanks,
Ian





Define the motion using a vector. The position coordinates are given by:
x = r*cos(theta)
y = r*sin(theta)
where r is the distance traveled and theta is the angle. You can get more description here[^]. You'll also have to assign a velocity.
I'm the ocean. I'm a giant undertow.





Beat me to it.
(Within 3 minutes, more than 3 hours from the original question, what are the chances of that?)
Matthew Butler





Pretty low I would imagine....wacky!
I'm the ocean. I'm a giant undertow.






Just use basic geometry/maths...
nextXpos = lastXpos + speed * sin(angle);
nextYpos = lastYpos  speed * cos(angle);
[angle is measured from the vertical, clockwise]
The only things you need to remember are:
> Math.Sin and Math.Cos take the angle argument in radians not degrees.
> Sin and Cos return double precision numbers: which may round to 0 or 1 if you are using integer positions and therefore the tank will not move as you want.
Hope this helps.
Matthew Butler






Edmundisme wrote: Thanks!
Well, should be tanks, instead...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke





Hello,
i have set of 2D points and i want to offset with a given distance (like offset command in AutoCAD)
i do not know how to deal with corners. i have searched on Internet, there are advanced methods like straight skeletons etc. but my polyline is not self crossing and no holes in it.
Is there any simple method? any references?
Best Regards.
Bekir





Why can't you just iterate through the points and add your offset to each one? It seems like this should translate the corners along with everything else.






beko wrote: Just translating the edges with the offset distance will not work.
Why not?
beko wrote: I have found an algorithm not tested throughly, but it is working at least for my very simple 3 points polyline test
What kind of test you did?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke





Hello,
At the end, it is a translation however it must be implemented with respect to the normals, as far as i read through if it is a parametric curve then it is rather complicated. If you like to see how much it can further get complicated, you can have a look at the link below.
http://timeguy.com/cradekfiles/emc/liu2007_line_arc_offset.pdf[^]
for the test, i have just created a polyline with three points and used the algorithm from Eduardo in my earlier reply, and compared it with AutoCAD output
Best Regards.





That paper seems to give a good description of how to do it. It's complicated, you will have lots of cases  you'll just have to get used to it.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





There is no simple solution to this problem, the best known general solution, is to create capsules between consecutive point pairs of your polyline where the capsule width is the offset, then union the capsule outlines. The capsule may be centered around the edge or it may be biased towards one side of the edge it is really up to the end requirement. For the union operation use something like Alan Murta's Generic Polygon Clipper library.
If you know your polyline is enclosed and represents a convex polygon, then simply calculate the centroid, then offset each edge by the product of the desired offset amount and the vector composed of the midpoint of the edge at hand minus the centroid.
A simple example can be found here:
http://www.codeproject.com/KB/recipes/Wykobi.aspx





Thank you for the all answers,
I will have a look at it.
Best Regards.





For 0 < a, b < 1, if it makes a difference.
Thanks!





It is only periodic is a/b is rational and then it is fairly easy to work out.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."





If you consider the wave form:
y(t) = A*sin(w*t + q)
A is the amplitude of the wave (height up the y axis)
q is the phase shift of the wave (left/right shift along the x axis)
t is a variable
w is the angular frequency
Angular frequency equals to 2*PI*f > where f is the frequency of the wave.
The period of the wave (t) is 1/f. (t = 1/f)
A Cosine wave is just a Sine wave with a 90 degree phase shift.
Cheers,





Since cos(ax) sin(bx) = 1/2 sin((a+b)x) + 1/2 cos((ab)x)
should be (a+b)/(ab) rationale.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
 Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
 Iain Clarke





im trying to convert Quaternion to Euler but i dont have appropriate code, i searched on lots of sites but their converting code do not match with converting back, mean, if i convert from Quaternion to Euler then i convert back the result value to Quaternion, i got different output, here is my code
public static float[] ToEuler(double tmp_x, double tmp_y, double tmp_z,double tmp_w)
{
float[] Euler = new float[3];
double sqr_X = tmp_x * tmp_x;
double sqr_Y = tmp_y * tmp_y;
double sqr_Z = tmp_z * tmp_z;
double sqr_W = tmp_w * tmp_w;
const double radian = 180 / Math.PI;
double check = tmp_x * tmp_y + tmp_z * tmp_w;
double unit = sqr_X + sqr_Y + sqr_Z + sqr_W;
if (check > 0.499 * unit)
{
Euler[0] = 0;
Euler[1] = (float)(radian * Math.Atan2(tmp_x, tmp_w));
Euler[2] = (float)90;
return Euler;
}
else if (check < 0.499 * unit)
{
Euler[0] = 0;
Euler[1] = (float)(radian * Math.Atan2(tmp_x, tmp_w));
Euler[2] = (float)90;
return Euler;
}
Euler[0] = (float)(radian * (Math.Atan2(2 * (tmp_x * tmp_w + tmp_y * tmp_z), (sqr_X  sqr_Y + sqr_Z + sqr_W))));
Euler[1] = (float)(radian * (Math.Asin(2 * (tmp_x * tmp_z  tmp_y * tmp_w))));
Euler[2] = (float)(radian * (Math.Atan2(2.0 * (tmp_x * tmp_y + tmp_z * tmp_w), (sqr_X  sqr_Y  sqr_Z + sqr_W))));
return Euler;
}
public static float[] ToEulerA(double x, double y, double z, double w)
{
double sqw = w * w;
double sqx = x * x;
double sqy = y * y;
double sqz = z * z;
double unit = sqx + sqy + sqz + sqw;
double test = x * y + z * w;
double RX = 0;
double RY = 0;
double RZ = 0;
if (test > 0.499 * unit)
{
RX = 2 * Math.Atan2(x, w);
RY = Math.PI / 2;
RZ = 0;
}
else if (test < 0.499 * unit)
{
RX = 2 * Math.Atan2(x, w);
RY = Math.PI / 2;
RZ = 0;
}
else
{
RX = Math.Atan2(2 * y * w  2 * x * z, sqx  sqy  sqz + sqw);
RY = Math.Asin(2 * test / unit);
RZ = Math.Atan2(2 * x * w  2 * y * z, sqx + sqy  sqz + sqw);
}
RX = 180 / Math.PI * RX;
RY = 180 / Math.PI * RY;
RZ = 180 / Math.PI * RZ;
return new float[] { (float)RX, (float)RY, (float)RZ };
}
im not sure which one is correct or both are incorrect...
any idea to solve this ?
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaKi?TV.C\y<p?jxsgb$f4ia>

128 bit encrypted signature, crack if you can






unfortunately i got code from that site, that site converter have some incorrect conversion, eg. at the end of page you will find a java converter, write real = 1, i = 1, and output will be 116.56505117707799, now put this 116.56505117707799 in Euler to Quaternion converter on another page and now result is completely different, why ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaKi?TV.C\y<p?jxsgb$f4ia>

128 bit encrypted signature, crack if you can





You could just reference Microsoft.DirectX



