Rotate point around a point with angle

I want to rotate vertex point (blue point) to the new position around the second position with an angle between first and second position in order to make mesh looks better.

how can i do that?? i use

private Vector3 MoveAroundPointWithAngle(Vector3 wantedP, Vector3 aroundP, float angle)	
{
		
  float newX = Mathf.Cos(angle)*(wantedP.x-aroundP.x) - Mathf.Sin(angle) * (wantedP.y-aroundP.y) + aroundP.y;

  float newY = Mathf.Sin(angle)*(wantedP.x-aroundP.x) - Mathf.Cos(angle) * (wantedP.y-aroundP.y) + aroundP.y;

  float newZ = wantedP.z;

  return new Vector3(wantedP.x+newX,wantedP.y+newY,newZ);
}

the new point i want vertex point to move is unknown

Vector3 wantedP is original vertex point and Vector3 aroundP is the second position.

alt text

125alt text125

Quaternions are the way to go when you need something done that includes vectors and rotations. Check em out in script reference:

You may find it difficult to understand how quaternions work internally. Just use their methods straight-forward, don’t bother yourself with details. :slight_smile:

You’ve got a flipped sign in the equation. The standard rotation matrix is:

cos -sin
sin  cos

You flipped the bottom right to a negative. But, jakovd’s advice is good – often easier, and a just a tiny bit CPU slower, to say Quaternion R = Quaternion.LookRotation(wantP-aroundP); and then use it: p2=R*p2;, which “applies” the rotation to a point.

@sakamotomiwa could you explain why are you trying to rotate these vertices through the script? Maybe you are facing the problem that would be much easier to solve using some 3D modeling tool…
I have no clue what is it that you are showing us with your pictures, mate :slight_smile:

ok , with my friend help, i can make it correctly now.

Vector3 oldDirection is (second position - first position) and angle as degree

“Rotate vector around a point with angle”


private Vector3 RotateVector2D(Vector3 oldDirection, float angle)   
{
        float newX = Mathf.Cos(angle*Mathf.Deg2Rad) * (oldDirection.x) - Mathf.Sin(angle*Mathf.Deg2Rad) * (oldDirection.y);   
        float newY = Mathf.Sin(angle*Mathf.Deg2Rad) * (oldDirection.x) + Mathf.Cos(angle*Mathf.Deg2Rad) * (oldDirection.y);	    
		float newZ = oldDirection.z;    
		return new Vector3(newX, newY, newZ);   
}