- Home /
plotting points ellipse) relative to transform of another game object
hi all, i am plotting an ellipse using the code attached to this question, and it works great! but i need to be able to plot the ellipse based on a different rotation. im plotting the points on the x,z plane, and need to be able to plot it from a different starting y rotation , but i cant figure out how to do it. i dont know whether there is some whay to change or add to the basic ellipse plotting code, to change its whole rotation, or somehow use an empty game object as a reference transform, and plot local to that?
thanks, paul uk
public void plotellipse(float radiusA, float radiusB){
float perimeter = ellipseperimeter (radiusA, radiusB);
perimeter = Mathf.Round (perimeter);
Debug.Log (perimeter);
float segments = 360f / perimeter;
Debug.Log (segments);
for (int i = 0; i < segments; i++) {
float x = Mathf.Sin (Mathf.Deg2Rad * angle) * radiusA;
float z = Mathf.Cos (Mathf.Deg2Rad * angle) * radiusB;
GameObject newsphere = Instantiate (sphere, new Vector3 (x, 0f, z), Quaternion.identity);
angle += (360f / segments);
}
Answer by Mudiman · Oct 17, 2017 at 10:21 PM
@gaiastellar, if I understand your question, you can modify the code on line 11 to GameObject newsphere = Instantiate (sphere, new Vector3 (x, 0f, z) + new Vector3(0f, desiredYValue, 0f), Quaternion.identity) as GameObject;
Let me know if it helps.
Your answer
![](https://koobas.hobune.stream/wayback/20220612134121im_/https://answers.unity.com/themes/thub/images/avi.jpg)