Death Star: Difference between revisions

From Rosetta Code
Content added Content deleted
(openscad)
Line 49: Line 49:
}
}


/*Subtract an overlapping sphere with a diameter of 40km
/*Subtract an overlapping sphere with a diameter of 40
The resultant hole will be smaller than this, because we only
The resultant hole will be smaller than this, because we only
only catch the edge
only catch the edge

Revision as of 15:52, 29 March 2011

Task
Death Star
You are encouraged to solve this task according to the task description, using any language you may know.

Death Star is a task to display a region that consists of a large sphere with part of a smaller sphere removed from it as a result of geometric subtraction. (This will basically produce a shape like a "death star".)

Brlcad

<lang brlcad>

  1. We need a database to hold the objects

opendb deathstar.g y

  1. We will be measuring in kilometers

units km

  1. Create a sphere of radius 60km centred at the origin

in sph1.s sph 0 0 0 60

  1. We will be subtracting an overlapping sphere with a diameter of 40km
  2. The resultant hole will be smaller than this, because we only
  3. only catch the edge

in sph2.s sph 0 90 0 40

  1. Create a region named deathstar.r which consists of big minus small sphere

r deathstar.r u sph1.s - sph2.s

  1. We will use a spherical material texture with rgb colour 224,224,224
  2. and zero inheritance

mater deathstar.r spm 224 224 224 0

  1. Clear the wireframe display and draw the deathstar

B deathstar.r

  1. We now trigger the raytracer to see our finished product

rt

</lang>

Openscad

<lang openscad> // We are performing geometric subtraction

difference() {

 // Create the primary sphere of radius 60 centred at the origin
 translate(v = [0,0,0]) {
   sphere(60);
 }
 /*Subtract an overlapping sphere with a diameter of 40
    The resultant hole will be smaller than this, because we only
    only catch the edge
 */
 translate(v = [0,90,0]) {
   sphere(40);
 }

} </lang>