# Examples

## Problem: Find the intersection of a cylinder and a plane

The intersection of a cylinder and a plane is the projection of the bottom (top, respectively) circle onto the plane - which is an ellipse. Following example uses the EllipticalCone class to visualize a circular cylinder. The projected ellipse (green) and the edge of the sliced cylinder are identical.

## Solution using V#

1.    public static void CylinderPlaneIntersection()
2.     {
3.         // Create an elliptical cone (a circular cylinder, in this case)
4.         // height of the cylinder is 5
5.         Ellipse bottomEllipse = new Circle(
6.             new Point(0, 0, 0), 1, new Vector3d(0, 0, 1)).ToEllipse();
7.         EllipticalCone cylinder = new EllipticalCone(bottomEllipse, 5);
8.
9.         // We don't want the covers here:
10.         cylinder.HasCover = false;
11.
12.         // the slicing plane
13.         Plane pl = new Plane(new Point(0, 0, 2), new Vector3d(1, 1, 2));
14.
15.         // calculate the projection of the (circular) bottom ellipse
16.         // onto the plane (this is the intersection of the cylinder and
17.         // the slicing plane!)
18.         Ellipse el = bottomEllipse.
19.             ProjectParallelOn(pl, bottomEllipse.NormalVector);
20.
21.         // 50 triangles forming the surface of the cone:
22.         List<Triangle> cylinderSurface = cylinder.GetSurface(50);
23.
24.         // A list containing the sliced surface
25.         List<Triangle> slicedCylinder = new List<Triangle>();
26.
27.         // slice the elliptical cone
28.         for ( int i = 0; i < cylinderSurface.Count; i++ )
29.         {
31.                 (cylinderSurface[i].Slice(pl, Triangle.SliceMethod.KeepBelow));
32.         }
33.
34.         // Visualize-----------------------------------------------------------
35.         // Make a scene
36.         Scene sc = new Scene();
37.
38.         // A layer for the sliced elliptical cone:
39.         Scene.Layer cylinerLayer = new Scene.Layer("sliced_cylinder", 1);
40.
41.         // A layer for the slicing plane:
42.         Scene.Layer planeLayer = new Scene.Layer("slicing_plane", 2);
43.
44.         // A layer for the intersection ellipse
45.         Scene.Layer ellipseLayer = new Scene.Layer("intersection_ellipse", 3);
46.
47.         // add all to the scene