It\'s been 10 years since I did any math like this... I am programming a game in 2D and moving a player around. As I move the player around I am trying to calculate the poin
Recommend:
public static Vector3 RotatePointAroundPivot(Vector3 point, Vector3
pivot, Vector3 angles)
{
return Quaternion.Euler(angles) * (point - pivot) + pivot;
}
The answer should be exactly opposite.
X = Xc + rSin(angle)
Y = Yc + rCos(angle)
where Xc and Yc are circle's center coordinates and r is the radius.
I also needed this to form the movement of the hands of a clock in code. I tried several formulas but they didn't work, so this is what I came up with:
So the formula would be
x=Cx+(r*cos(d/(180/PI))
y=Cy+(r*sin(d/(180/PI))
where x and y are the points on the circumference of a circle, Cx and Cy are the x,y coordinates of the center, r is the radius, and d is the amount of degrees.
I wanted to share how your contributions above helped me produce an Arduino LCD compass. I hope this is the right etiquette...I just joined stackoverflow so I could thank you fine folks.
While standing on the shoulders of the geometry giants above I was able to produce this sample compass: Arduino TFT compass with multiple bearings
The code for the function I called repeatedly (for different bearings you see in tiny yellow text) is written in Arduino (kinda like "C")...and is pretty translatable:
void PaintCompassNeedle( int pBearingInDegrees, int pRadius, TSPoint pCentrePt ) {
// ******************************************************************************
// * Formula for finding pointX on the circle based on degrees around the circle:
// * x_oncircle = x_origin + radius * cos (degrees * pi / 180)
// * y_oncircle = y_origin - radius * sin (degrees * pi / 180) //minus explained
// * Thanks to folks at stackoverflow...standing on the shoulders of giants. :)
float bearingInRads = (pBearingInDegrees) * PI / 180;
// Degrees vs Rads...The math folks use Rads in their formulas
// *******************************************************************
// * bearingPt is the point on the circle that we are trying to find
TSPoint bearingPt;
// Find the X on the circle starting with orgin (centre)
bearingPt.x = pCentrePt.x + pRadius * sin(bearingInRads);
// Notice the "minus" R * cos()...because TFT the y is upside down bearingPt.y =
pCentrePt.y - pRadius * cos(bearingInRads);
// * Extra Explanation: The TFT is the graphical display I'm using and it
// * calculates x & y from the top left of screen (portrait mode) as (0,0)
// * ...so by Subtracting from the Y orgin...I flip it vertically
// * Other folks using x,y as increasing to the right and up respectively
// * would keep the plus sign after the pCentrePt.y
// *************************************************************************
// ***************************************************************
// * This part will change for the final product...but leaving
// * it because when call numerous times it shows it working for
// * a number of different quadrants (displaying yellow degrees text)
tft.fillCircle( bearingPt.x, bearingPt.y, 5, RED);
tft.setCursor( bearingPt.x, bearingPt.y );
tft.setTextSize( 1 );
tft.setTextColor( YELLOW );
tft.print( pBearingInDegrees );
TSPoint innerPt;
innerPt.x = pCentrePt.x + pRadius/2 * sin(bearingInRads);
innerPt.y = pCentrePt.y - pRadius/2 * cos(bearingInRads);
tft.drawLine(innerPt.x, innerPt.y, bearingPt.x, bearingPt.y, RED);
}