Мне известно, что этот вопрос задавался ранее, и я проверил много сообщений, и я понимаю, что моя математика недостаточно хороша для решения этой проблемы.
У меня есть круг, который является центральной точкойпри х = 0,0 и у = 0,0.Основываясь на степени 270 в этом примере, я хочу разместить блок x на x & y в указанном градусе от центральной точки.Я просто не могу понять это правильно, даже с примерами, которые я нашел.Ниже приведен текущий код, который я тестирую, а также результат теста на 270 градусов, x-box расположен неправильно, поскольку это не угол 270 градусов.
Буду признателен за любую помощь.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class testscript : MonoBehaviour
{
public Image im1, im2;
public Text im1txt, im2txt, deg;
private float degree = 270f;
private float x, y;
void Start()
{
im1.rectTransform.anchoredPosition = new Vector2(0f, 0f);
im1txt.text = im1.rectTransform.anchoredPosition.ToString();
deg.text = degree + " degrees";
x = 0f + (100 * Mathf.Cos(degree * Mathf.PI / 360f));
y = 0f + (100 * Mathf.Sin(degree * Mathf.PI / 360f));
im2.rectTransform.anchoredPosition = new Vector2(x, y);
im2txt.text = im2.rectTransform.anchoredPosition.ToString();
}
}
I have tested the two suggestions below and basically get the same result as all the others. Let me visualize the result I get with the last test I done:
const float deg_to_rad = 2f * Mathf.PI / 360f;
var radians = degree * deg_to_rad;
x = 0 + Mathf.Cos(radians) * 100;
y = 0 + Mathf.Sin(radians) * 100;
Here is the result:
[![enter image description here][2]][2]
Solution is, Sin and Cos was swapped. Thanks J.Lengel:
float x = 1f + (100 * Mathf.Sin(angelDegree * Mathf.PI / 180));
float y = -14f + (100 * Mathf.Cos(angelDegree * Mathf.PI / 180));