# Position particles in a Teardrop-Shape

Hello everyone,

i need to position particles in a Teardrop-Shape (3D).
For this purpose i need an parametric equation for an Vector.

So far i have this equation:

``````    public Vector3 Eval(float theta, float phi)
{
Vector3 p;

p.x = 0.5f * (1f - Mathf.Cos(theta)) * Mathf.Sin(theta) * Mathf.Cos(phi);
p.y = 0.5f * (1f - Mathf.Cos(theta)) * Mathf.Sin(theta) * Mathf.Sin(phi);
p.z = Mathf.Cos(theta);

return (p);
}
``````

But i don’t know how to use it in the right way.
I want to set the position dependent of three parameters:

first: distance from the center
second: height
third: radius (if you look from top to bottom)

I hope i could express myself in the right way because I am not an English native speaker.

Can anyone help me?

I am grateful for any hint.

Here, try this

It’s up to you how many you emit per frame - just call the code in a loop to emit many times per frame.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class teardrop : MonoBehaviour {

private ParticleSystem ps;
public float sizeMultiplier = 1.0f;
public float heightMultiplier = 1.0f;

// Use this for initialization
void Start () {
ps = GetComponent<ParticleSystem>();

var main = ps.main;
main.startSpeed = 0.0f;
main.startSize = 0.05f;

var emission = ps.emission;
emission.enabled = false;
}

// Update is called once per frame
void Update () {

float theta = Random.Range(0.0f, 1.0f);
float phi = Random.Range(0.0f, 1.0f);

ParticleSystem.EmitParams emitParams = new ParticleSystem.EmitParams();
emitParams.position = Eval(theta * Mathf.PI * 2.0f, phi * Mathf.PI) * sizeMultiplier;
emitParams.startColor = new Color(0.0f, phi, 0.0f);
ps.Emit(emitParams, 1);
}

private Vector3 Eval(float theta, float phi)
{
float sinT = Mathf.Sin(theta);
float cosT = Mathf.Cos(theta);

Vector3 p;

p.x = 0.5f * (1f - cosT) * sinT * Mathf.Cos(phi) * radiusMultiplier;
p.y = 0.5f * (1f - cosT) * sinT * Mathf.Sin(phi) * radiusMultiplier;
p.z = cosT * heightMultiplier;

return (p);
}
}
``````

Thank you richardkettlewell,

I am not expected full Code, but thanks. This will do it.
I will try it in the next Time when i find some. I will give again Feedback then.

I am really grateful to you.
Maybe you can explain some things of the Eval function?
I know that this is related to the Spherical Coordinates of an Sphere:

But what parameters or constants have the effect that this is an Tearshape?
Probably all parameters which are not similar, but what are there effects?
Probably I have some deficits in Math here.

I probably ask too much. But it is also important to me to understand it.
Maybe you can answer or you can also leave it (I you do not necessarily want to steal time from you).

No problem, good luck!

As you have cited, the Sine and Cosine graphs are very useful for creating circular shapes.
You can see that being used for the X and Y axes in your code. The Z is created using a different part of the Cosine graph, to create the tear, instead of a regular sphere.

It may help you to look at the graphs of Sine and Cosine. You should be able to visualise how they are appearing in the final teardrop shape.