# Rotating Sprite Around A Point Without Messing Its Drawing Point

I am trying to draw and rotate an arrow sprite based on a point,around a static circle body without messing its drawing starting point. Arrow should be ﻿directed to the same direction with user touch point,static body center vector.

Let me explain it with an example.

This is how i calculate arrow drawing point:

fun powerIndicatorDownPointCalculator(playerPosition: Vector2,touchPosition: Vector2,distanceBetweenTouchPointAndPlayer:Float):Vector2{
// player position is static body center,touch position is touch point.

val playerPositionHolder = playerPosition.cpy()

val abVector = playerPosition.sub(touchPosition);

val normalizedAbVector = Vector2(abVector.x/distanceBetweenFingerAndPlayer,abVector.y/distanceBetweenFingerAndPlayer)

Gdx.app.log("normalized ab vector",normalizedAbVector.toString())

var newPointX  = playerPositionHolder.x + pointToAddX
var newPointY = playerPositionHolder.y + pointToAddY
Gdx.app.log("NEW POINT", Vector2(newPointX,newPointY).toString())

return Vector2(newPointX,newPointY)

}


Here is a simple gif showing it:

https://i.ibb.co/TvHBMh9/MNML-November19-041320-AM.gif

This is how i calculate C point to use later on rotation(?)

 fun calculateAimingPoint(playerPosition: Vector2,touchPosition: Vector2):Vector2{
//playerPosition is staticbody center
val abVector = playerPosition.sub(touchPosition);

val secondPos = blackBody.position.cpy()
return cPointPosition

}


This is what i wrote for rotation but for sure it is wrong since not working as i wanted:

var angle = atan2(aimingPoint.y - blackBody.position.y, aimingPoint.x - blackBody.position.x ) *180/ PI ;
//aiming point is C point, blackBody is static body
if (angle > 90)
{
angle = 450 - angle;
}
else
{
angle = 90 - angle;
}

// powerIndicator.setOrigin(????) // setOrigin is for rotation but i dont now what to write here.

angle = angle*-1
powerIndicator.rotation = angle.toFloat()


What i actually wanna achieve is this: https://i.ibb.co/gDM9H3L/MNML-November19-042729-AM-2.gif

• I am unsure if i understand your question. You want to draw an arrow that points in the direction the stone is going to fly, based on some touch input? if so you can subtract the stones center from your touch point and normalize that to get the arrows direction. scale that by the radius of the stone and add it to it's center to get the base point of the arrow. add the direction from before to that and you have the tip of your arrow. atan2 the direction from before to get an angle in radians. – Jonas Beck Nov 19 '19 at 16:24
• actually this is exactly what i am trying to do with above code – lastpeony4 Nov 19 '19 at 18:09

  var degrees = (Math.atan2((aimingPoint.x - xDownPoint).toDouble(), -(aimingPoint.y - yDownPoint).toDouble()) * 180.0 / Math.PI - 180.0f).toFloat()