원의 둘레에 스프라이트 추가 (Add a sprite on circumference of a circle)


문제 설명

원의 둘레에 스프라이트 추가 (Add a sprite on circumference of a circle)

원의 둘레에 무작위로 스프라이트를 생성하고 싶지만 몇 시간 동안 조사한 후에도 해결책을 찾지 못했습니다. 그것이 내가 지금까지 할 수 있는 일입니다.

여기에 이미지 설명 입력

이 공식을 사용했습니다.

Sprite * pin = Sprite::create("pin.png");
pin‑>setPosition(Vec2((_circle‑>getContentSize().width/2)*(0.7/3), _circle‑>getContentSize().height*0.7));

Sprite * pin2 = Sprite::create("pin.png");
pin2‑>setPosition(Vec2((_circle‑>getContentSize().width/2)*(0.6/3), _circle‑>getContentSize().height*0.6));

Sprite * pin3 = Sprite::create("pin.png");
pin3‑>setPosition(Vec2((_circle‑>getContentSize().width/2)*(0.8/3), _circle‑>getContentSize().height*0.8));

Sprite * pin4 = Sprite::create("pin.png");
pin4‑>setPosition(Vec2((_circle‑>getContentSize().width/2)*(0.9/3), _circle‑>getContentSize().height*0.9));

Sprite * pin5 = Sprite::create("pin.png");
pin5‑>setPosition(Vec2((_circle‑>getContentSize().width/2)*(1/3), _circle‑>getContentSize().height));

_circle‑>addChild(pin);
_circle‑>addChild(pin2);
_circle‑>addChild(pin3);
_circle‑>addChild(pin4);
_circle‑>addChild(pin5);

그러나 나는 그런 것을 원합니다(샘플 이미지에서는 할 수 없는 정확한 각도로)

여기에 이미지 설명 입력

정확한 해결책을 제시해 주십시오. 시간 내주셔서 감사합니다!


참조 솔루션

방법 1:

First, it's "circumference" not "circumstance" (that will help with your searches)

Second, you are using the size of the image, not the circle inside the image.

Third, you will need to use basic trigonometry for the solution. Determining points on a circle require the use of sin and cos functions. After you find the center of the circle and it's radius, these should be easy to calculate with just a little bit of research.

방법 2:

Basic trig stuff ‑‑ sin and cos are your friends.

Example:

const float circle_x = ...;
const float circle_y = ...;
const float circle_radius = ...;
const float angle = ...;
const float x = cos(angle)*circle_radius + circle_x;
const float y = sin(angle)*circle_radius + circle_y;

// Draw stuff at (x, y).

(by NargisJimuser4842163)

참조 문서

  1. Add a sprite on circumference of a circle (CC BY‑SA 2.5/3.0/4.0)

#C++ #geometry #Android #cocos2d-x






관련 질문

파일의 암호화/복호화? (Encryption/ Decryption of a file?)

이상한 범위 확인 연산자가 있는 C++ typedef (C++ typedef with strange scope resolution operator)

개체 배열 매개변수--오류: '문자' 필드에 불완전한 유형이 있습니다. (Object array parameter--error: field ‘letters’ has incomplete type)

C++에서 메모리 삭제 (Deleting memory in c++)

C++ 프로그램을 실행할 수 없습니다. No se ejecuta el programa (C++ i can't run a program. No se ejecuta el programa)

컴파일 시 변수의 이름과 수명 (Name and lifetime of variables at compile time)

control-c 후 Visual Studio 콘솔 프로그램 충돌 (visual studio console program crashes after control-c)

멤버 변수에 std::enable_if 또는 유사한 메서드 사용 (Using std::enable_if or similar method on member variable)

ifstream input_file(filename); (I am receiving an error "no matching function to call" in the line ifstream input_file(filename);)

ESP8266에서 잠시 실행하면 JsonData 크기가 0이 됩니다. (JsonData size becomes zero after awhile of running in ESP8266)

합에 대한 속도 문제(제수의 합) (Speed problem for summation (sum of divisors))

벡터 벡터에서 하위 벡터의 첫 번째 값을 찾기 위해 begin() 및 end() 반복기의 범위를 지정하는 방법은 무엇입니까? (How to specify a range for begin() and end() iterators to find first value of sub vector in a vector of vectors?)







코멘트