Let's try to shift, scale, rotate objects

Let's try to shift objects

Array x in my_model(x[3], a[1]) includes coordinates in three dimensions. The corresponding relationship is,

x[1] -> x
x[2] -> y
x[3] -> z

The following is an equation of a solid sphere which has its center as the origin and a radius of 5: 5^2 - (x^2 + y^2 + z^2) >= 0 The model in HyperFun:

my_model(x[3], a[1])
{
  sphere = 5.0^2 - (x[1]^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_shift_0.jpg

What is the difference between these two equations: 5^2 - ((x-5)^2 + y^2 + z^2) >= 0 and 5^2 - (x^2 + y^2 + z^2) >= 0? We will experiment with two equations in HyperFun.

my_model(x[3], a[1])
{
  sphere = 5.0^2 - ((x[1]-5.0)^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_shift_x_plus_5.jpg

Then what is the difference between these two equations: 5^2 - ((x+5)^2 + y^2 + z^2) >= 0 and 5^2 - (x^2 + y^2 + z^2) >= 0? We will experiment with two equations in HyperFun.

my_model(x[3], a[1])
{
  sphere = 5.0^2 - ((x[1]+5.0)^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_shift_x_minus_5.jpg

The result of experiments with HyperFun shows us that replacing x with x-5 is equal to moving only 5 in the positive direction of the x-axis, and replacing x with x+5 is equal to moving only 5 in the negative direction of the x-axis.

Question:

Given the equation 100 - (x^2y^2 + y^2z^2+z^2x^2) >= 0, how is this equation moved only 5 in the positive direction of the x-axis?

Answer:

100 - ((x-5)^2y^2 + y^2z^2 + z^2(x-5)^2) >= 0

Let’s try to shift the sphere in the direction of the y-axis, the z-axis. In HyperFun, there is only one operation for shifting in 3D space: hfShift3D

Let's try to scale objects

First let’s make a sphere, which has its center as the origin and a radius of 5.

my_model(x[3], a[1])
{
  sphere = 5.0^2 - (x[1]^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_shift_0.jpg
5^2 - (x^2 + y^2 + z^2) >= 0

What is the dirference between these two equations: 5^2 - ((x/2)^2 + y^2 + z^2) >= 0 and 5^2 - (x^2 + y^2 + z^2) >= 0? We will experiment in HyperFun, replacing x[1] with x[1]/2.

my_model(x[3], a[1])
{
  sphere = 5.0^2 - ((x[1]/2)^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_scale_x_double.jpg
5^2 - ((x/2)^2 + y^2 + z^2) >= 0

What is the dirference between these two equations: 5^2 - ((x*2)^2 + y^2 + z^2) >= 0 and 5^2 - (x^2 + y^2 + z^2) >= 0? We will experiment in HyperFun, replacing x[1] with x[1]*2.

my_model(x[3], a[1])
{
  sphere = 5.0^2 - ((x[1]*2)^2 + x[2]^2 + x[3]^2);
    
  my_model = sphere;
}

hyperfun.org_tut_html_e_images_sphere_scale_x_half.jpg
5^2 - ((x*2)^2 + y^2 + z^2) >= 0

As the result of experimenting with HyperFun, a sphere is scaled twice with the x-axis, replacing x with x/2, a sphere is scaled 1/2 times with the x-axis, replacing x with x*2. Let’s try to scale the sphere with y-axis, z-axis in the same way.

In HyperFun, there is only one operation for scaling: hfScale3D

Let's try to rotate objects

Rotating at s radian in three dimension around the z-axis is described in HyperFun as follows, (s radian is pi*s/180 degree.)

x' = x cos(s) + y sin(s) 
y' = y cos(s) - x sin(s) 
z' = z

We will experiment with the upper expressions in HyperFun.

my_model(x[3], a[1])
{
  array xt[3];
  pi = 3.14159;
  deg2rad = pi/180.0;

  sphere1 = 3.0^2 - ((x[1] - 5)^2 + x[2]^2 + x[3]^2);

  xt[1] = x[1]*cos(deg2rad*90.0) + x[2]*sin(deg2rad*90.0);
  xt[2] = x[2]*cos(deg2rad*90.0) - x[1]*sin(deg2rad*90.0);
  xt[3] = x[3];

  sphere2 = 3.0^2 - ((xt[1] - 5)^2 + xt[2]^2 + xt[3]^2);
    
  my_model = sphere1 | sphere2;
}

hyperfun.org_tut_html_e_images_sphere_rotate.jpg

The sphere1 is a sphere which has the center of (5, 0, 0) and a radius of 3. The sphere2 is the sphere1 which is rotated at a 90 angle around the z-axis. As the result of using the upper expressions, we can make a sphere rotate at a 90 angle around the z-axis. The following expressions are ones of rotation around y-axis and z-axis.

Let’s try to use them.

Expressions of rotation around y-axis.

x' = x cos(s) - z sin(s) 
y' = y 
z' = x cos(s) + z sin(s)

Expressions of rotation around x-axis.

x' = x 
y' = y cos(s) + z sin(s) 
z' = z cos(s) - y sin(s)

In HyperFun, there are three operations for rotation: hfRotate3DZ (rotation around z-axis), hfRotate3DY (rotation around y-axis), hfRotate3DX (rotation around x-axis).

hyperfun/tut_trans.txt · Last modified: 2008/12/11 10:21 by admin
This site contains HyperFun and other software that is free to use and modify under the provisions of the CGPL agreement unless otherwise stated.
Project hosted by the Digital Materialization Group
HyperFun CGPL HyperFun on SourceForge Creative Commons License Valid CSS Driven by DokuWiki