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!
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
{
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 };
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;
}
public static double Calc(PropertySelector Property, PropertySelector From, double Value)
{
switch (Property)
{
case PropertySelector.Area:
switch (From)
{
case PropertySelector.Area:
return Value;
case PropertySelector.Circumference:
return Math.Pow(Value, 2) / (4 * Math.PI);
case PropertySelector.Diameter:
return Math.PI * (Value / 2) * (Value / 2);
case PropertySelector.Radius:
return Math.PI * Value * Value;
}
break;
case PropertySelector.Circumference:
switch (From)
{
case PropertySelector.Area:
return (2 * Math.PI) * Math.Sqrt(Value / Math.PI);
case PropertySelector.Circumference:
return Value;
case PropertySelector.Diameter:
return 2 * Math.PI * (Value / 2);
case PropertySelector.Radius:
return 2 * Math.PI * Value;
}
break;
case PropertySelector.Diameter:
switch (From)
{
case PropertySelector.Area:
return Math.Sqrt(Value / Math.PI) * 2;
case PropertySelector.Circumference:
return Value / Math.PI;
case PropertySelector.Diameter:
return Value;
case PropertySelector.Radius:
return 2 * Value;
}
break;
case PropertySelector.Radius:
switch (From)
{
case PropertySelector.Area:
return Math.Sqrt(Value / Math.PI);
case PropertySelector.Circumference:
return (Value / Math.PI) / 2;
case PropertySelector.Diameter:
return Value / 2;
case PropertySelector.Radius:
return Value;
}
break;
}
throw new Exception("Should not have happened...");
}
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;
}
}
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);
}
}
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);
}
}
public Point Centre
{
get
{
return this.centre;
}
set
{
this.centre = value;
}
}
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);
}
}
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!