Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This class has everything that I have made so far.



Objective: Get The Intersect & IntersectAt Methods Functioning

I am challenged in this regard, I'm not the greatest math wizard and could use some help with the formulas and programmatic operations which make such functions operate in resonance that this class is a circle and not a square.



Question:

So, How would you get the Intersect, IntersectAt, and Contains function working for the circle to work with circles and the circle to work with rectangles?



Thank You!

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
using Android.Graphics;
using Android.Graphics.Drawables;

namespace Android.Graphics
{
    /// <summary>
    /// It is just a basic circle with properties that are editable, yet still binded together.
    /// </summary>
    public class Circle : IParcelable
    {        
        
        private Point centre;
        private Double area;
        private Double diameter;
        private Double radius;
        private Double circuference;
        public enum PropertySelector { Area, Diameter, Radius, Circumference };    
        
        /// <summary>
        /// Create A Cricle From Property-Value Relations.
        /// </summary>
        /// <param name="Property">Geometrical Property To Scale.</param>
        /// <param name="Value">The Size Of That Property</param>
        public Circle(PropertySelector Property, Double Value, Point Centre) {
            switch (Property)
            {
                case PropertySelector.Area:
                    this.Area = Value;
                    UpdateProperty(PropertySelector.Diameter, PropertySelector.Area);
                    UpdateProperty(PropertySelector.Radius, PropertySelector.Area);
                    UpdateProperty(PropertySelector.Circumference, PropertySelector.Area);
                    break;
                case PropertySelector.Diameter:
                    this.Diameter = Value;
                    UpdateProperty(PropertySelector.Area, PropertySelector.Diameter);
                    UpdateProperty(PropertySelector.Radius, PropertySelector.Diameter);
                    UpdateProperty(PropertySelector.Circumference, PropertySelector.Diameter);
                    break;
                case PropertySelector.Radius:
                    this.Radius = Value;
                    UpdateProperty(PropertySelector.Area, PropertySelector.Radius);
                    UpdateProperty(PropertySelector.Diameter, PropertySelector.Radius);
                    UpdateProperty(PropertySelector.Circumference, PropertySelector.Radius);
                    break;
                case PropertySelector.Circumference:
                    this.circuference = Value;
                    UpdateProperty(PropertySelector.Area, PropertySelector.Circumference);
                    UpdateProperty(PropertySelector.Diameter, PropertySelector.Circumference);
                    UpdateProperty(PropertySelector.Radius, PropertySelector.Circumference);
                    break;
            }
            this.centre = Centre;
        }

        public Circle(PropertySelector Property, Double Value) : this(Property, Value, new Point(0, 0)) { }
        public Circle(Point Centre) : this(PropertySelector.Radius, 12, Centre) { }
        public Circle() : this(PropertySelector.Radius, 12, new Point(0, 0)) { }
        public Circle(Circle C)
        {
            this.area = C.Area;
            this.centre = C.Centre;
            this.circuference = C.Circumference;
            this.diameter = C.Diameter;
            this.radius = C.Radius;
        }
        /// <summary>
        /// Calculates A Given Property From Another Property.
        /// </summary>
        /// <param name="Property">The Property To Figure.</param>
        /// <param name="From">The Property To Figure From.</param>
        /// <param name="Value">The Value Of The Property To Figure From.</param>
        /// <returns>Value Of The Property Figured.</returns>
        public static double Calc(PropertySelector Property, PropertySelector From, double Value)
        {
            switch (Property)
            {
                case PropertySelector.Area:
                    switch (From)
                    {
                        case PropertySelector.Area: // Calculate Area From Area
                            return Value;
                        case PropertySelector.Circumference: // Find The Area, Given Circumference
                            return Math.Pow(Value, 2) / (4 * Math.PI);
                        case PropertySelector.Diameter: // Find The Area, Given The Diameter
                            return Math.PI * (Value / 2) * (Value / 2);
                        case PropertySelector.Radius: // Find Area, Given Radius
                            return Math.PI * Value * Value;

                    }
                    break;
                case PropertySelector.Circumference:
                    switch (From)
                    {
                        case PropertySelector.Area:// Circumference From Area
                            return (2 * Math.PI) * Math.Sqrt(Value / Math.PI);
                        case PropertySelector.Circumference: // Circumference From Circumference
                            return Value;
                        case PropertySelector.Diameter: // Circumference From Diameter
                            return 2 * Math.PI * (Value / 2);
                        case PropertySelector.Radius: // Circumference From Radius
                            return 2 * Math.PI * Value;
                    }
                    break;
   
                case PropertySelector.Diameter:
                    switch (From)
                    {
                        case PropertySelector.Area: // Calculate Diameter Of Circle, Given Its Area
                            return Math.Sqrt(Value / Math.PI) * 2;
                        case PropertySelector.Circumference: // Calculate Diameter Of Circle, Given Its Circumference
                            return Value / Math.PI;
                        case PropertySelector.Diameter: // Calculate Diameter Of Circle, Given Its Diameter
                            return Value;
                        case PropertySelector.Radius: // Calculate Diameter Of Circle, Given Its Radius
                            return 2 * Value;
                    }
                    break;
                case PropertySelector.Radius:
                    switch (From)
                    {
                        case PropertySelector.Area: // Calculate Raduis From Area
                            return Math.Sqrt(Value / Math.PI);
                        case PropertySelector.Circumference: // Calculate Radius From Circumference
                            return (Value / Math.PI) / 2;
                        case PropertySelector.Diameter: // Calculate Radius From Diameter
                            return Value / 2;
                        case PropertySelector.Radius: // Calculate Radius From Radius
                            return Value;
                    }
                    break;
            }
            throw new Exception("Should not have happened...");
        }

        /// <summary>
        /// Updates One Property From Another Property Of The Same Class.
        /// </summary>
        /// <param name="Property">The Property To Be Updated</param>
        /// <param name="From">Update That Property From This Property</param>
        private void UpdateProperty(PropertySelector Property, PropertySelector From)
        {
            Double Value = 0;
            switch (From)
            {
                case PropertySelector.Area:
                    Value = area;
                    break;
                case PropertySelector.Diameter:
                    Value = diameter;
                    break;
                case PropertySelector.Radius:
                    Value = radius;
                    break;
                case PropertySelector.Circumference:
                    Value = circuference;
                    break;
            }

            Value = Calc(Property, From, Value);

            switch (Property)
            {
                case PropertySelector.Area:
                    area = Value;
                    break;
                case PropertySelector.Diameter:
                    diameter = Value;
                    break;
                case PropertySelector.Radius:
                    radius = Value;
                    break;
                case PropertySelector.Circumference:
                    circuference = Value;
                    break;
            }
        }

        /// <summary>
        /// Get or set the circle by it's diameter.
        /// </summary>
        public Double Diameter
        {
            get
            {
                return diameter;
            }
            set
            {
                this.diameter = value;
                UpdateProperty(PropertySelector.Area, PropertySelector.Diameter);
                UpdateProperty(PropertySelector.Circumference, PropertySelector.Diameter);
                UpdateProperty(PropertySelector.Radius, PropertySelector.Diameter);
            }
        }

        /// <summary>
        /// Get or set the circle by it's radius.
        /// </summary>
        public Double Radius
        {
            get
            {
                return this.radius;
            }
            set
            {
                this.radius = value;
                UpdateProperty(PropertySelector.Area, PropertySelector.Radius);
                UpdateProperty(PropertySelector.Circumference, PropertySelector.Radius);
                UpdateProperty(PropertySelector.Diameter, PropertySelector.Radius);
            }
        }

        /// <summary>
        /// Binds into radius, the values are just that equal on an object that is of infinate and no space.
        /// </summary>
        public Point Centre
        {
            get
            {
                return this.centre;
            }
            set
            {
                this.centre = value;
            }
        }

        /// <summary>
        /// Get or set the circle by it's area.
        /// </summary>
        public Double Area
        {
            get
            {
                return this.area;
            }
            set
            {
                this.area = value;
                UpdateProperty(PropertySelector.Circumference, PropertySelector.Area);
                UpdateProperty(PropertySelector.Diameter, PropertySelector.Area);
                UpdateProperty(PropertySelector.Radius, PropertySelector.Area);
            }
        }

        /// <summary>
        /// Get or set the circle by it's circumference.
        /// </summary>
        public Double Circumference
        {
            get
            {
                return this.Circumference;
            }
            set
            {
                this.Circumference = value;
                UpdateProperty(PropertySelector.Area, PropertySelector.Circumference);
                UpdateProperty(PropertySelector.Diameter, PropertySelector.Circumference);
                UpdateProperty(PropertySelector.Radius, PropertySelector.Circumference);
            }
        }

        public Boolean isEmpty()
        {
            return true;
        }

        public void offset(int dx, int dy)
        {
            throw new NotImplementedException();
        }

        public void offsetTo(int newLeft, int newTop)
        {
            throw new NotImplementedException();
        }

        public void readFromParcel(Parcel _in)
        {
            throw new NotImplementedException();
        }

        public void set(Circle src)
        {
            throw new NotImplementedException();
        }

        public void set(PropertySelector Property, Double Value, Point Centre)
        {
            throw new NotImplementedException();
        }

        public void setEmpty()
        {
            throw new NotImplementedException();
        }

        public Boolean setIntersect(Circle a, Circle b)
        {
            throw new NotImplementedException();
        }

        public Boolean setIntersect(Circle a, Rect b)
        {
            throw new NotImplementedException();
        }

        public Boolean setIntersect(Circle a, int left, int top, int right, int bottom)
        {
            throw new NotImplementedException();
        }

        public void sort()
        {
            throw new NotImplementedException();
        }

        public String toShortString()
        {
            throw new NotImplementedException();
        }

        public String toString()
        {
            throw new NotImplementedException();
        }

        public static Circle unflattenFromString(String str)
        {
            throw new NotImplementedException();
        }


        public void union(PropertySelector Property, Double Value, Double Centre)
        {
            throw new NotImplementedException();
        }

        public void union(Circle c)
        {
            throw new NotImplementedException();
        }

        public void union(int left, int top, int right, int bottom)
        {
            throw new NotImplementedException();
        }

        public void union(Rect r)
        {
            throw new NotImplementedException();
        }

        public void union(int x, int y)
        {
            throw new NotImplementedException();
        }

        public Double Width
        {
            get
            {
                return diameter;
            }
        }


        public Double Height
        {
            get
            {
                return diameter;
            }
        }

        public IntPtr Handle => throw new NotImplementedException();

        public static Boolean Intersect(Circle Circle1, int left, int top, int right, int bottom)
        {
            throw new NotImplementedException();
        }

        public static Boolean Intersect(Circle Circle, Rect Rect)
        {
            throw new NotImplementedException();
        }

        public static Boolean Intersect(Circle Circle1, Circle Circle2)
        {
            throw new NotImplementedException();
        }

        public Boolean Intersect(Circle Circle)
        {
            throw new NotImplementedException();
        }

        public int DescribeContents()
        {
            throw new NotImplementedException();
        }

        public void WriteToParcel(Parcel dest, [GeneratedEnum] ParcelableWriteFlags flags)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            throw new NotImplementedException();
        }
    }


   

}


What I have tried:

I have designed the class from this point and after that, I reached a point where I couldn't even read the algebraic or trig expressions that I was reading online. It wasn't even remotely intelligible to me. That is why I am asking for help on the:

public void IntersectAt(Circle)
public bool Intersect(Circle, Square)
public bool Intersect(Circle, Circle)
public float Contains(Square){ ... //returns percentage of square circle contains) }
public float Contains(Circle){ ... //same for square, but with circle instead. }

Its about the geometry math.

Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900