2

The following code is called every 50ms.

// Start point
private double x;
private double y;
private double z;

private double y1;
@Override
public void run() {
    double x1 = Math.cos(y1);
    double z1 = Math.sin(y1);
    double y2 = 4D - y1;
    double x2 = Math.sin(y2);
    double z2 = Math.cos(y2);
    // First new point
    double pX1 = x + x1;
    double pY1 = y + y1;
    double pZ1 = z + z1;
    // Second new point
    double pX2 = x + x2;
    double pY2 = y + y2;
    double pZ2 = z + z2;

    if (y1 > 4D) {
        y1 = 0D;
    } else {
        y1 = y1 + 0.1D;
    }
}

Here is the output in a game. It generates two helices. I cannot control more than the radius.

I am looking for code I can easily customize to fit my preferences. How do I control the following aspects?

  • How fast the helix rises.

  • Where the helix begins.

spongebob
  • 8,370
  • 15
  • 50
  • 83

3 Answers3

2

One part of the helix begins at:

(x, y, z) = (1.0, 0.0, 0.0)

And the other at:

(x, y, z) = (-0.8, 4.0, -0.7)

And the particle rises at a rate of 0.1 (from y1 = y1 + 0.1D).

So, to control how fast the particles rise, just change this value.

To control where the helix begins you need to change the angle. For example, add some value to the sines and cosines. Like this:

Math.cos(y1 + dy);

To make more rotations before restarting from the ground you can multiply the angle. Make it twice as fast:

Math.cos(2 * y1);
spongebob
  • 8,370
  • 15
  • 50
  • 83
2

helix is circular shape with 'linear' movement of the plane

  • you use plane xz as helix base and y axis as height
  • so you need:
  • r - radius
  • d - distance between two screws (the y movement after full circle)
  • t - parameter <0,1> determining the position on helix
  • h0,h1 - start end height of helix (y-axis)
  • a0 - angular start position [rad]

Now how to get the point on helix as function of parameter these parameters

aa=fabs(h1-h0)*2.0*M_PI/d; // angular speed coefficient
// if you need opposite angular direction then add aa=-aa;
x=r*cos(a0+aa*t);
z=r*sin(a0+aa*t);
y=h0+((h1-h0)*t);
  • aa can be precomputed once
  • now if t=0.0 then you get the start point of helix
  • if t=1.0 then you got the endpoint of helix
  • so speed is just how much you add to t during animation per timer cycle
  • d controls number of screw loops
  • h1-h0 is the helix height
  • code is in C++ (sorry I am not a JAVA coder)
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • 1
    @Joiner if you need also angular end position then you have to tweak `aa` so that `a0+aa=a1+k*2.0*M_PI` where `k=...-2,-1,0,1,2,...` which will distort `d` a bit but that should not be visible too much unles you are measuring it ... – Spektre Jan 29 '15 at 08:28
1

Helix is circular shape with progressive Y value.

// Start point
private double x;
private double y;
private double z;

private double degree;
private double rY;
@Override
public void run() {
    // We use the same formula that is used to find a point of a circumference
    double rX = Math.cos(degree);
    double rZ = Math.sin(degree);
    // New point
    double pX = x + rX;
    double pY = y + rY;
    double pZ = z + rZ;

    if (degree > 2D * Math.PI) {
        degree = 0D;
    } else {
        degree = degree + 0.2D;
    }
    if (pY > 2D) {
        pY = 0D;
    } else {
        pY = pY + 0.02D;
    }
}

spongebob
  • 8,370
  • 15
  • 50
  • 83