Skip to content

3D Shapes Volume , Area , Moving ( Three Dimensional Shapes , Geometry C# )

Notifications You must be signed in to change notification settings

merisahakyan/ThreeDShapes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Working with Three dimentional shapes.

Class library ThreeDimentionalShapes contains abstract class AbstractShapes, which has 3 abstract members: property point (coordinates x,y,z); method Volume() (which calculates volume of shape) and method Area() (which calculates area of shape).

public abstract class AbstractShapes
{
    public abstract Point point { get; set; }
    public abstract float Volume();
    public abstract float Area();
}

ThreeDimentionalShapes contains 2 structures: Point (for determining x,y,z coordinates) and MoveDirections (for determining axis angles with x,y,z axises ) .
The struct MoveDirections allows you to determine any axis in distance with 3 arguments: alpha (angle of given and x axis), betta (for given and y axis) , gamma (for given and z axis).

public struct Point
{
    public float x { get; set; }
    public float y { get; set; }
    public float z { get; set; }

    public Point(float x,float y,float z)
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }
}
  
public struct MoveDirections
{      
       public float alpha { get; set; }
       public  float betta { get; set; }
       public  float gamma { get; set; }
        public MoveDirections(float a,float b,float c)
        {
            alpha = a;
            betta = b;
            gamma=c;
        }
} 

We have IMuveable interface , which provides shape's moving. It contains methods MoveTo(),MoveBy(),MoveByAxis().

  • Method MoveTo() allows you to move the shape to given location.
  • Method MoveBy() allows you to move the shape by given difference coordinates dx,dy,dz.
  • Method MoveByAxix() allows you to move shape by any axis in distance with 2 arguments.Float d is the length of locomotion by given axis
public interface IMoveable
{
    void MoveTo(float x, float y, float z);
    void MoveTo(Point p);
    void MoveBy(float dx, float dy, float dz);
    void MoveByAxis(MoveDirections md, float d);
}

Classes Ellipsoid and Cone are inherited from AbstractShape abstract class and IMuveable interface.
For using this class library is necessary to add namespace ThreeDimentionalShapes : using ThreeDimentionalShapes;

Here are trial code

using System;
using ThreeDimentionalShapes;

namespace Testing
{
    class Program
    {
        static void Main(string[] args)
        {
            float pi = (float)Math.PI;

            Ellipsoid e = new Ellipsoid();
            Console.WriteLine($"Ellipsoid with sizes 1,1,1 \n Volume is equal to {e.Volume()} \n Area is equal to {e.Area()} \n Coordinates are ({e.point.x};{e.point.y};{e.point.z}) \n");

            e.MoveTo(2.3f, 4.3f, 1f);
            Console.Write($"After apply method MoveTo, ");
            e.PrintPosition();

            e.MoveBy(-2.3f, -4.3f, -1f);
            Console.Write($"After apply method MoveBy,");
            e.PrintPosition();

            MoveDirections md = new MoveDirections(0, pi/2, pi/2);
            e.MoveByAxis(md, 3);
            Console.Write($"After apply method MoveByAxis, moving ellipsoid by X axis ");
            e.PrintPosition();

        }
    }
}

The result is:

result

About

3D Shapes Volume , Area , Moving ( Three Dimensional Shapes , Geometry C# )

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages