public override void OnCreate(GameObject obj) { if (Missile == null) { Position = CastArgs.End; } else { Position = Missile.EndPosition; StartMissilePos = Missile.Position; } PrimaryCircle = new Circle { Radius = SpellData.Radius, BorderWidth = 3, Color = Color.White }; SecondaryCircle = new Circle { Radius = 10, Color = Color.LawnGreen }; }
public static void DrawFilledCircle( Circle c, Graphics g, ImageSpace i, Brush b ) { Rectangle? rect = Rect( c, i ); if( rect == null ) return; g.FillEllipse( b, rect.Value ); }
public static Vector2[] CircleIntersection(Circle A, Circle B) { float Distance = Vector2.Distance(A.Center, B.Center); if (Distance > A.Radius + B.Radius) { return null; } float a = (float)(Math.Pow((double)A.Radius, 2) - Math.Pow((double)B.Radius, 2) + Math.Pow((double)Distance, 2)) / (Distance * 2f); float b = Distance - a; float h = (float)Math.Sqrt(Math.Pow((double)A.Radius, 2) - Math.Pow((double)a, 2)); Vector2 P2 = A.Center + ((a * (B.Center - A.Center)) / Distance); Vector2 Intersection1 = new Vector2() { X = P2.X + h * (B.Center.Y - A.Center.Y) / Distance, Y = P2.Y - h * (B.Center.X - A.Center.X) / Distance }; Vector2 Intersection2 = new Vector2() { X = P2.X - h * (B.Center.Y - A.Center.Y) / Distance, Y = P2.Y + h * (B.Center.X - A.Center.X) / Distance }; if (float.IsNaN(Intersection1.X)) { return null; } Vector2[] VecArray = new Vector2[] { Intersection1, Intersection2, new Vector2(a, b), P2 }; return VecArray; }
public override void UpdateDependencies(double currentTime) { base.UpdateDependencies(currentTime); if (Visible) { if (_line == null) { _line = new Line(); _circle = new Circle {Radius = Radius}; _circle.AttachTo(this, false); _line.AttachTo(_circle, false); _line.RelativePoint1 = new Point3D(0, 0); _line.RelativePoint2 = new Point3D(Radius, 0); } if (!_added) { ShapeManager.AddLine(_line); ShapeManager.AddCircle(_circle); _added = true; } } if (!Visible && _line != null) { ShapeManager.Remove(_line); ShapeManager.Remove(_circle); _added = false; } }
static void Main() { var shapes = new Shape[numberOfShapes]; for (int i = 0; i < shapes.Length; i++) { switch (vladoRandoma.Next() % 3) { case 0: shapes[i] = new Triangle(widths[vladoRandoma.Next(0, widths.Length)], heights[vladoRandoma.Next(0, heights.Length)]); break; case 1: shapes[i] = new Rectangle(widths[vladoRandoma.Next(0, widths.Length)], heights[vladoRandoma.Next(0, heights.Length)]); break; case 2: shapes[i] = new Circle(heights[vladoRandoma.Next(0, heights.Length)]); break; default: break; } } foreach (var item in shapes) { Console.WriteLine(item.ToString().Replace(',', '.')); } }
public override void OnTick() { if (!Manager.IsInGame) return; var greenCircle = new Circle(CIRCLE_RADIUS, Color.FromArgb(0x8f, 0, 0xff, 0), Color.FromArgb(0x8f, 0, 0xff, 0)); var redCircle = new Circle(CIRCLE_RADIUS, Color.FromArgb(0x8f, 0xff, 0, 0), Color.FromArgb(0x8f, 0xff, 0, 0)); var blueCircle = new Circle(CIRCLE_RADIUS, Color.Black, Color.FromArgb(0x8f, 0, 0, 0xff), isFilled: false); var units = Manager.Objects.Where(x => x.IsValid && (x.IsUnit || x.IsPlayer)).OfType<WoWUnit>(); foreach (var u in units) { if (u.IsNeutral || u.IsHostile) redCircle.Add(u.Location.ToVector3()); else greenCircle.Add(u.Location.ToVector3()); blueCircle.Add(u.Location.ToVector3()); var color = (u.InLoS ? Color.FromArgb(0x8f, 0, 0xff, 0) : Color.FromArgb(0x8f, 0xff, 0, 0)); var line = new Line(); line.Add(Manager.LocalPlayer.Location, color); line.Add(u.Location, color); Rendering.RegisterResource(line); } Rendering.RegisterResource(redCircle); Rendering.RegisterResource(greenCircle); Rendering.RegisterResource(blueCircle); }
public override void Initialize() { Health = 10; Texture = tortoiseTexture; Color = Color.White; DrawLayer = .3f; CollisionLayer = 1; CollidesWithLayers = new int[] { 2 }; Origin = new Vector2(24.5f, 24.5f); Hitbox = new Circle(Center, 12f); CollidesWithLayers = new int[1] { 2 } ; CollidedObjects = new List<GameObject>(); DeletionBoundary = new Vector2(200, 200); mainEmitter = new BulletEmitter(this, Vector2.Zero, false); mainEmitter.LockedToParentPosition = true; mainEmitter.LockPositionOffset = (Origin / 2); pointValue = 500; scriptManager = thisScene.scriptManager; OnOuterCollision += CollisionHandling; base.Initialize(); base.Initialize(); }
/// <summary> /// Create a new intersection between a segment and a circle. /// </summary> /// <param name="i">The point of intersection.</param> /// <param name="c">The circle.</param> /// <param name="s">The segment.</param> public CircleSegmentIntersection(Point i, Circle c, Segment s) : base() { intersect = i; circle = c; segment = s; }
public bool CollidesWith(Circle circle) { float radiusSum = Radius + circle.Radius; IVector2D distance = Center.Substract(circle.Center); return distance.Length() <= radiusSum; }
/// <summary> /// Determines if a circle intersects a circle. /// </summary> /// <returns>True if the circle and circle overlap. False otherwise.</returns> public bool Intersects(Circle circle) { float dist = Vector2.Distance(Center, circle.Center); float minDist = Radius + circle.Radius; return dist <= minDist; }
/// <summary> /// Constructor for the Missle Enemy. /// </summary> /// <param name="position"></param> public MineEnemy(Vector2 position, Player playerOne, Texture2D mineSpawnerTexture, Texture2D mineTexture) { m_mineEnemyTexture = mineSpawnerTexture; m_mineTexture = mineTexture; m_pPlayer = playerOne; m_position = position; m_spriteScale = 0.35f; m_dimensions = new Vector2(128, 128) * m_spriteScale; m_origin = (m_dimensions / 2.0f) / m_spriteScale; m_maxVelocity = 0.0f; m_turningSpeed = 150.0f; m_wanderPosition = new Vector2(); m_detectionRadius = new Circle(m_position, 100); m_collisionRadius = new Circle(m_position, m_dimensions.X / 2 * m_spriteScale); m_directionChange = 2.0f; m_addMineCountdown = 2.0f; m_lerpColour = 0.0f; m_mineList = new List<Mine>(); m_slowMotion = false; }
public static Point2d PP(Object object_i, Object object_j, Circle circle) { if (object_i is Circle) { Circle circle_i = object_i as Circle; if (object_j is Circle) { Circle circle_j = object_j as Circle; return PlacingPoint.Calc(new Circle() { X = circle_i.X, Y = circle_i.Y, R = circle_i.R + circle.R }, new Circle() { X = circle_j.X, Y = circle_j.Y, R = circle_j.R + circle.R }); } else { StripLine strip_line_j = object_j as StripLine; return PlacingPoint.Calc(new Circle() { X = circle_i.X, Y = circle_i.Y, R = circle_i.R + circle.R }, new StripLine() { PX = strip_line_j.PX + strip_line_j.VY * circle.R, PY = strip_line_j.PY - strip_line_j.VX * circle.R, VX = strip_line_j.VX, VY = strip_line_j.VY }); } } else { StripLine strip_line_i = object_i as StripLine; if (object_j is Circle) { Circle circle_j = object_j as Circle; return PlacingPoint.Calc(new StripLine() { PX = strip_line_i.PX + strip_line_i.VY * circle.R, PY = strip_line_i.PY - strip_line_i.VX * circle.R, VX = strip_line_i.VX, VY = strip_line_i.VY }, new Circle() { X = circle_j.X, Y = circle_j.Y, R = circle_j.R + circle.R }); } else { StripLine strip_line_j = object_j as StripLine; return PlacingPoint.Calc(new StripLine() { PX = strip_line_i.PX + strip_line_i.VY * circle.R, PY = strip_line_i.PY - strip_line_i.VX * circle.R, VX = strip_line_i.VX, VY = strip_line_i.VY }, new StripLine() { PX = strip_line_j.PX + strip_line_j.VY * circle.R, PY = strip_line_j.PY - strip_line_j.VX * circle.R, VX = strip_line_j.VX, VY = strip_line_j.VY }); } } }
public void ConstructorsEqualityTest() { Circle circle1 = new Circle(84, 64, 32); Circle circle2 = new Circle(52, 32, 64, false); Assert.True(circle1.Equals(circle2), "the circles should be equal"); Assert.Equal(circle1.GetHashCode(), circle2.GetHashCode()); //the circles should generate the same hash code }
public void DoClick(Circle circle) { if (Physics.CircleCicleCollision(circle, GaucheCercle) && Valeur > Min) Valeur = Math.Max(Min, Valeur - Increment); else if (Physics.CircleCicleCollision(circle, DroiteCercle) && Valeur < Max) Valeur = Math.Min(Max, Valeur + Increment); }
/// <summary> /// tests that the circle.Intersects method properly determines whether 2 /// circles Intersects /// </summary> public void TestCirclesIntersects() { //create a few circles Circle circle1 = new Circle { Center = new Point(0,0), Radius = 2}; Circle circle2 = new Circle { Center = new Point(0,0), Radius = 3}; Circle circle3 = new Circle { Center = new Point(6, 0), Radius = 3 }; Circle circle4 = new Circle { Center = new Point(1, 1), Radius = 3 }; //non-Intersectsing circles Assert.IsFalse(circle1.Intersects(circle3)); Assert.IsFalse(circle3.Intersects(circle1)); Assert.IsFalse(circle1.Intersects(null)); //touching circles Assert.IsTrue(circle2.Intersects(circle3)); Assert.IsTrue(circle3.Intersects(circle2)); //Intersectsing circles Assert.IsTrue(circle1.Intersects(circle2)); Assert.IsTrue(circle2.Intersects(circle1)); Assert.IsTrue(circle2.Intersects(circle4)); Assert.IsTrue(circle4.Intersects(circle2)); Assert.IsTrue(circle1.Intersects(circle4)); Assert.IsTrue(circle4.Intersects(circle1)); Assert.IsTrue(circle3.Intersects(circle4)); Assert.IsTrue(circle4.Intersects(circle3)); }
public override void ExecuteFigureCreationCommand(string[] splitFigString) { switch (splitFigString[0]) { case "circle": { Vector3D center = Vector3D.Parse(splitFigString[1]); double radius = double.Parse(splitFigString[2]); currentFigure = new Circle(center, radius); break; } case "cylinder": { Vector3D bottom = Vector3D.Parse(splitFigString[1]); Vector3D top = Vector3D.Parse(splitFigString[2]); double radius = double.Parse(splitFigString[3]); currentFigure = new Cylinder(bottom, top, radius); break; } } base.ExecuteFigureCreationCommand(splitFigString); }
public static void GenImage() { int size = 1000; Bitmap image = new Bitmap( size, size ); ImageSpace i = new ImageSpace( size, size ); double b = 1.1; i.XMin = -b; i.XMax = b; i.YMin = -b; i.YMax = b; Vector3D cen = HoneycombPaper.CellCenBall; cen = H3Models.BallToUHS( cen ); Sphere[] simplex = Simplex( ref cen ); Sphere inSphere = InSphere( simplex ); using( Graphics g = Graphics.FromImage( image ) ) foreach( int[] reflections in AllCells() ) { Sphere clone = inSphere.Clone(); foreach( int r in reflections ) clone.Reflect( simplex[r] ); Sphere ball = new Sphere(); Circle3D inSphereIdealBall = ball.Intersection( clone ); Circle3D inSphereIdealUHS = H3Models.BallToUHS( inSphereIdealBall ); Circle inSphereIdeal = new Circle { Center = inSphereIdealUHS.Center, Radius = inSphereIdealUHS.Radius }; using( Brush brush = new SolidBrush( Color.Blue ) ) DrawUtils.DrawFilledCircle( inSphereIdeal, g, i, brush ); } image.Save( "threefifty.png", ImageFormat.Png ); }
public static void Main() { Square square = new Square(0, 0, 10); Rectangle rect = new Rectangle(0, 0, 10, 12); Circle circle = new Circle(0, 0, 5); if (square is IShape) { Console.WriteLine("{0} is IShape", square.GetType()); } if (rect is IResizable) { Console.WriteLine("{0} is IResizable", rect.GetType()); } if (circle is IResizable) { Console.WriteLine("{0} is IResizable", circle.GetType()); } IShape[] shapes = { square, rect, circle }; foreach (IShape shape in shapes) { shape.SetPosition(5, 5); Console.WriteLine( "Type: {0}; surface: {1}", shape.GetType(), shape.CalculateSurface()); } }
public static void ThreeCircleIntersectPoints(Circle c1, Circle c2, Circle c3, List<Vector3> insectPoints) { Vector3[] ps1 = Circle.TwoCircleIntersectPoints(c1, c2); if (ps1 != null) { foreach (Vector3 v in ps1) { float length = (v - c3.mCenter).magnitude; if (length <= c3.mRadius) { bool haveSame = false; foreach (Vector3 vv in insectPoints) { if (Mathf.Abs(vv.x - v.x) < 0.0001 && Mathf.Abs(vv.y - v.y) < 0.0001 && Mathf.Abs(vv.z - v.z) < 0.0001) { haveSame = true; } } if (haveSame == false) { insectPoints.Add(v); } } } } }
public void CircleXml() { Circle c = new Circle(new Point(1, 3), 3); SimplTypesScope circleTransaltionScope = SimplTypesScope.Get("circleTScope", typeof(Circle), typeof(Point)); TestMethods.TestSimplObject(c, circleTransaltionScope, Format.Xml); }
public static ICollection<Vector2> CollidedSurfaceNormals(Circle circle, ICollection<AABB> aabbs) { var surfaceNormals = new List<Vector2>(); restartLoop: foreach (var aabb in aabbs) { Vector2 nearestVector = NearestVectorBetweenCircleAndAABB(aabb, circle); if (NearestVectorIntersects(nearestVector, circle)) { //if (surfaceNormals == EMPTY) surfaceNormals = new List<Vector2>(); var surfaceNormal = Vector2.Normalize(nearestVector); if (!surfaceNormals.Contains(surfaceNormal)) { surfaceNormals.Add(surfaceNormal); PushCircleApartFromAABB(circle, nearestVector, 1.0f); goto restartLoop; } } } return surfaceNormals; }
public ChoicesHorizontalSlider(string label, List<string> choices, int startingIndex) { Choices = choices; ChoiceIndex = startingIndex; DecrementRep = new Image("WidgetNext") { Origin = Vector2.Zero, Effect = SpriteEffects.FlipHorizontally, SizeX = 4 }; IncrementRep = new Image("WidgetNext") { Origin = Vector2.Zero, SizeX = 4 }; ValueText = new Text(Choices[ChoiceIndex], @"Pixelite") { SizeX = 2 }; Label = new Text(label, @"Pixelite") { SizeX = 2 }; LongestChoice = new Text(@"Pixelite") { SizeX = 2 }; foreach (var choice in Choices) { if (choice.Length > LongestChoice.Data.Length) LongestChoice.Data = choice; } DecrementCircle = new Circle(Vector3.Zero, DecrementRep.AbsoluteSize.X / 2); IncrementCircle = new Circle(Vector3.Zero, IncrementRep.AbsoluteSize.X / 2); SpaceForLabel = 200; SpaceForValue = 200; }
public Player() : base() { ID = "player"; PlayerEventCallback = null; _lastEvent = PlayerEvent.None; RenderLayer = Render_Layer; RenderDepth = Render_Depth; _mapBounds = Rectangle.Empty; CollisionBoundingCircle = new Circle(Vector2.Zero, Body_Collision_Radius); Collidable = true; Visible = true; _motionEngine = new PlayerMotionEngine(); MotionEngine = _motionEngine; _isSmashingSmashBlocks = false; _hasTouchedGoalFlag = false; IsExitingLevel = false; LastRaceRestartPointTouched = null; TutorialStepTrigger = null; ResetCollisionFlags(); }
public CelestialBodyExplosion() { Handler = new IntegerHandler(CheckEnemiesHit); Output = new Dictionary<int, Enemy>(); CelestialBodyRectangle = new PhysicalRectangle(); CelestiablBodyRange = new Circle(Vector3.Zero, 0); }
public bool CanStructureBePlaced(Point location, int size, Unit builder, bool cutCorners) { List<PathNode> placingStructurePathNodes = new List<PathNode>(); Circle collisionCircle = new Circle(new Vector2(location.X * Map.TileSize + (size / 2) * Map.TileSize, location.Y * Map.TileSize + (size / 2) * Map.TileSize), size * Map.TileSize); //placingStructureCenterPoint = collisionCircle.CenterPoint; for (int x = location.X; x < location.X + size; x++) { for (int y = location.Y; y < location.Y + size; y++) { PathNode node = Rts.pathFinder.PathNodes[(int)MathHelper.Clamp(y, 0, Map.Height - 1), (int)MathHelper.Clamp(x, 0, Map.Width - 1)]; if (collisionCircle.Intersects(node.Tile)) { placingStructurePathNodes.Add(node); } } } // remove corners if (cutCorners) { placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X]); if (location.X + size <= Map.Width - 1) placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y, location.X + size - 1]); else return false; if (location.Y + size <= Map.Height - 1) placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X]); else return false; placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[location.Y + size - 1, location.X + size - 1]); } foreach (PathNode node in placingStructurePathNodes) { if (!node.Tile.Walkable || node.Blocked) return false; if (node.UnitsContained.Count > 0) { if (node.UnitsContained.Count == 1 && node.UnitsContained.ElementAt<Unit>(0) == builder) continue; else { bool allow = true; foreach (Unit unit in node.UnitsContained) { if (unit.Team != builder.Team) { allow = false; break; } } if (!allow) return false; } } } return true; }
public PowerUpSpawner(GameObject[] powerUpPrefabs, Circle gameArea, float spawnDelay = 30.0f) : base(spawnDelay) { this.powerUpPrefabs = powerUpPrefabs; this.gameArea = gameArea; this.spawnTimer = spawnDelay; }
private static void Main() { var circle = new Circle(5); Console.WriteLine(circle); var rect = new Rectangle(2, 3); Console.WriteLine(rect); }
public Vector2 CollisionPoint(Circle circle) { return new Vector2 { X = ((Center.X * circle.Radius) + (circle.Center.X * Radius)) / (Radius + circle.Radius), Y = ((Center.Y * circle.Radius) + (circle.Center.Y * Radius)) / (Radius + circle.Radius), }; }
public static bool CircleCollision(Circle circleA, Circle circleB) { float distance = Vector2.Distance(circleA.Position, circleB.Position); float radiusTotal = circleA.Radius + circleB.Radius; return (distance < radiusTotal); }
public void Initialize() { int size = 75; innercircle = new Circle(new Vector2(100 , screen.Height / options.ScaleFactor - 25), content.Load<Texture2D>("Img/Game/LSIC"), size, size); System.Threading.Thread.Sleep(10); outercircle = new Circle(new Vector2(100, screen.Height / options.ScaleFactor - 25), content.Load<Texture2D>("Img/Game/LSOC"), size, size); }
public void TestScaleCircleToNegativePercent() { Circle circle = new Circle(10, 15); circle.Scale(-5); }
public static void B(Circle circle) { }
/// <summary> /// Initializes a new instance of the <see cref="CircleResult"/> class. /// </summary> /// <param name="value">The value being examined.</param> internal CircleResult(Circle value) { this.value = value; }
static void Main(string[] args) { #region MyRegion //List<int> liste = new List<int>(); //liste.Add(3); //liste.Add(7); //liste.Add(5); //liste.Add(4); //foreach (var item in liste) //{ // Console.WriteLine(item); //} //Console.WriteLine("*********************"); ////Console.WriteLine(liste.Count); //liste.RemoveAt(0); //liste.Insert(1, 98); //liste.Reverse(); //foreach (var item in liste) //{ // Console.WriteLine(item); //} //if (!liste.Contains(95)) //{ // Console.WriteLine("liste içerisinde 95 sayısı mevcut değildir"); //} #endregion #region MyRegion int x = 3; float pi = 3.14f; double y = 6.15; decimal z = 5.67M; DateTime date = DateTime.Now; string isim = "Ali"; string[] isimler = new string[] { "Ali", "Veli", "Hasan" }; //List<int> sayilar = new List<int>(); //sayilar.Add(1); //sayilar.Add(2); List <string> iss = new List <string>(); List <Customer> customers = new List <Customer>(); #endregion #region MyRegion //Customer customer = new Customer("Ahmet", "Murat"); ////customer.name = "Ali"; ////customer.surname = "Tugrul"; //customer.ShowFullName(); //BankAccount bank = new BankAccount(1000); //Console.WriteLine("Bakiye = " + bank.BakiyeGoster()); //bank.ParaYatir(500); //Console.WriteLine("Bakiye = " + bank.BakiyeGoster()); //bank.ParaCek(200); //Console.WriteLine("Bakiye = " + bank.BakiyeGoster()); #endregion //FullTimeEmployee full = new FullTimeEmployee(); //PartTimeEmployee part = new PartTimeEmployee(); //MyClass c = new MyClass(); Circle c1 = new Circle(); c1.Radius = 5; Console.WriteLine(c1.CalculateArea()); Circle c2 = new Circle(); c2.Radius = 6; Console.WriteLine(c2.CalculateArea()); Console.ReadLine(); }
public Page5Row5Prob18(bool onoff, bool complete) : base(onoff, complete) { Point a = new Point("A", 0, 0); points.Add(a); Point b = new Point("B", 0, 4); points.Add(b); Point c = new Point("C", 0, 8); points.Add(c); Point d = new Point("D", 20, 8); points.Add(d); Point e = new Point("E", 18, 4); points.Add(e); Point f = new Point("F", 16, 0); points.Add(f); Point g = new Point("G", 16, 8); points.Add(g); Point x = new Point("X", 8, 4); points.Add(x); Point y = new Point("Y", 8, 0); points.Add(y); Segment xy = new Segment(x, y); segments.Add(xy); Segment fg = new Segment(f, g); segments.Add(fg); Circle circle = new Circle(x, 4.0); circles.Add(circle); List <Point> pts = new List <Point>(); pts.Add(a); pts.Add(b); pts.Add(c); collinear.Add(new Collinear(pts)); pts = new List <Point>(); pts.Add(c); pts.Add(g); pts.Add(d); collinear.Add(new Collinear(pts)); pts = new List <Point>(); pts.Add(d); pts.Add(e); pts.Add(f); collinear.Add(new Collinear(pts)); pts = new List <Point>(); pts.Add(b); pts.Add(x); pts.Add(e); collinear.Add(new Collinear(pts)); pts = new List <Point>(); pts.Add(a); pts.Add(y); pts.Add(f); collinear.Add(new Collinear(pts)); parser = new GeometryTutorLib.TutorParser.HardCodedParserMain(points, collinear, segments, circles, onoff); Angle angle = (Angle)parser.Get(new Angle(a, c, d)); Triangle tri = (Triangle)parser.Get(new Triangle(f, g, d)); CircleSegmentIntersection inter = (CircleSegmentIntersection)parser.Get(new CircleSegmentIntersection(y, circle, (Segment)parser.Get(new Segment(a, f)))); given.Add(new Strengthened(angle, new RightAngle(angle))); given.Add(new Strengthened(inter, new Tangent(inter))); given.Add(new Strengthened(tri, new RightTriangle(tri))); given.Add(new GeometricParallel((Segment)parser.Get(new Segment(c, d)), (Segment)parser.Get(new Segment(b, e)))); given.Add(new GeometricParallel((Segment)parser.Get(new Segment(c, d)), (Segment)parser.Get(new Segment(a, f)))); given.Add(new GeometricCongruentSegments((Segment)parser.Get(new Segment(d, e)), (Segment)parser.Get(new Segment(e, f)))); known.AddSegmentLength((Segment)parser.Get(new Segment(a, f)), 16); known.AddSegmentLength((Segment)parser.Get(new Segment(c, d)), 20); known.AddSegmentLength((Segment)parser.Get(new Segment(a, c)), 8); List <Point> wanted = new List <Point>(); wanted.Add(new Point("", 1, 1)); wanted.Add(new Point("", 15, 1)); wanted.Add(new Point("", 3, 7)); wanted.Add(new Point("", 10, 5)); goalRegions = parser.implied.GetAtomicRegionsByPoints(wanted); SetSolutionArea(144 - System.Math.PI * 8); }
public DynamicBody(Circle circle, UniformGridWorld world) : base(circle, world) { IsStatic = false; }
public void SetCircle(Circle circle) { Shape = circle; }
public static bool IntersectMovingCircleBox(Circle s, Box b, Vector2 movement, out float time) { // compute the AABB resulting from expanding b by sphere radius r var e = b.bounds; e.Inflate(s.Radius, s.Radius); // Intersect ray against expanded expanded Rectangle e. Exit with no intersection if ray // misses e, else get intersection point p and time t as result var ray = new Ray2D(s.position - movement, s.position); if (!e.RayIntersects(ref ray, out time) && time > 1.0f) { return(false); } // get the intersection point var point = ray.Start + ray.Direction * time; // compute which min and max faces of b the intersection point p lies outside of. Note, u and v cannot have the // same bits set and they must have at least one bit set among them. int u = 0, v = 0; if (point.X < b.bounds.Left) { u |= 1; } if (point.X > b.bounds.Right) { v |= 1; } if (point.Y < b.bounds.Top) { u |= 2; } if (point.Y > b.bounds.Bottom) { v |= 2; } // 'or' all set bits together into a bitmask (note u + v == u | v) var m = u + v; // if all 3 bits are set then point is in a vertex region if (m == 3) { // must now intersect segment against the capsules of the two edges meeting at the vert and return the best time, // if one or more hit // https://play.google.com/books/reader?printsec=frontcover&output=reader&id=VSoIBwAAAEAJ&pg=GBS.PA267 // https://github.com/noonat/hello/blob/580b986f3bb27b93645087441d2744eeb99d6d35/hello/collisions/Collision.hx#L675 //throw new NotImplementedException(); Debug.Log($"m == 3. corner {Time.FrameCount}"); } // if only one bit is set in m then point is in a face region if ((m & (m - 1)) == 0) { Debug.DrawHollowBox(point, 4, Color.Black, 0.4f); // do nothing. time from the expanded rect intersection is the correct time return(true); } // point is on an edge region. intersect against the capsule at the edge. return(true); }
public bool Intersect(Circle circle) { return(this.Center.Distance(circle.Center) <= circle.Radius + this.Radius); }
public void CellComplexExample() { this.Name = "Elements_Spatial_CellComplex_CellComplex"; // <example> // Assemble CellComplex from Grid2d var numLevels = 10; var levelHeight = 1; var cellSize = 2; var complex = new CellComplex(); var boundary = new Circle(new Vector3(), 10).ToPolygon(); var grid = new Grid2d(boundary, Vector3.Origin, Vector3.XAxis, Vector3.YAxis); var pathMaterial = new Material("Path", new Color(1, 0, 0, 0.75)); grid.U.DivideByFixedLength(cellSize); grid.V.DivideByFixedLength(cellSize); for (var i = 0; i < numLevels; i++) { foreach (var cell in grid.GetCells()) { foreach (var crv in cell.GetTrimmedCellGeometry()) { complex.AddCell((Polygon)crv, levelHeight, i * levelHeight, grid.U, grid.V); } } } // Draw base CellComplex foreach (var face in complex.GetFaces()) { this.Model.AddElement(new Panel(face.GetGeometry(), BuiltInMaterials.Mass)); } // Traverse CellComplex var start = new Vector3(15, 15, 15); var end = new Vector3(-15, -15, -15); // Draw lines from start and end to closest points, for reference foreach (var pt in new List <Vector3>() { start, end }) { var closest = complex.GetClosestVertex(pt).GetGeometry(); this.Model.AddElement(new ModelCurve(new Line(pt, closest), pathMaterial)); } var curCell = complex.GetClosestCell(start); var j = 0; // this shouldn't happen but in case of infinite traversal it's good to have some sanity check while (j < 500 && curCell != null) { var rep = new Representation(new[] { curCell.GetGeometry() }); this.Model.AddElement(new GeometricElement(new Transform(), pathMaterial, rep, false, Guid.NewGuid(), "Path")); curCell = curCell.GetClosestNeighbor(end); j += 1; } // </example> }
private CollisionInfo GetCircleOverlap(Circle other) { return(other.GetOverlap(this)); }
private void AbsoluteHandler(ref Manifold manifold, Rigidbody.Rigidbody a, Rigidbody.Rigidbody b) { Circle A = (Circle)a.Shape; Polygon B = (Polygon)b.Shape; manifold.ContactCount = 0; Vector2 center = B.Orientation.Transpose().Multiply(a.transform.position - b.transform.position); float separation = Mathf.NegativeInfinity; int faceNormal = 0; for (int i = 0; i < B.VertexCount; ++i) { float s = Vector2.Dot(B.Normals[i], center - B.Vertices[i]); if (s > A.Radius) { return; } if (s > separation) { separation = s; faceNormal = i; } } Vector2 v1 = B.Vertices[faceNormal]; int i2 = faceNormal + 1 < B.VertexCount? faceNormal + 1 : 0; Vector2 v2 = B.Vertices[i2]; if (separation < Mathf.Epsilon) { manifold.ContactCount = 1; manifold.Normal = -B.Orientation.Multiply(B.Normals[faceNormal]); manifold.Contacts = new Vector2[manifold.ContactCount]; manifold.Contacts[0] = manifold.Normal * A.Radius + (Vector2)a.transform.position; manifold.Penetration = A.Radius; return; } float dot1 = Vector2.Dot(center - v1, v2 - v1); float dot2 = Vector2.Dot(center - v2, v1 - v2); manifold.Penetration = A.Radius - separation; if (dot1 <= 0.0f) { if (Vector2.Distance(center, v1) > A.Radius) { return; } manifold.ContactCount = 1; manifold.Normal = B.Orientation.Multiply(v1 - center).normalized; manifold.Contacts = new Vector2[manifold.ContactCount]; manifold.Contacts[0] = B.Orientation.Multiply(v1) + (Vector2)b.transform.position; } else if (dot2 <= 0.0f) { if (Vector2.Distance(center, v2) > A.Radius) { return; } manifold.ContactCount = 1; manifold.Normal = B.Orientation.Multiply(v2 - center).normalized; manifold.Contacts = new Vector2[manifold.ContactCount]; manifold.Contacts[0] = B.Orientation.Multiply(v2) + (Vector2)b.transform.position; } else { Vector2 n = B.Normals[faceNormal]; if (Vector2.Dot(center - v1, n) > A.Radius) { return; } manifold.ContactCount = 1; manifold.Normal = -B.Orientation.Multiply(n); manifold.Contacts = new Vector2[manifold.ContactCount]; manifold.Contacts[0] = manifold.Normal * A.Radius + (Vector2)a.transform.position; } }
public void TestScaleCircleTo0Percent() { Circle circle = new Circle(10, 15); circle.Scale(0); }
///<summary>Добавляет диск на эту башню</summary> ///<param name="circle">диск</param> public void AddCircles(Circle circle) { circle.transform.position = PositionForNewCircle; _allCircles.Add(circle); }
public void TestCircleConstructorSanityChecksHeight() { Circle circle = new Circle(50, 0); }
public void TestCircleConstructorSanityChecksHeightPositivity() { Circle circle = new Circle(50, -1); }
public void TestCircleConstructorSanityChecksWidth() { Circle circle = new Circle(0, 50); }
public void TestCircleConstructorSanityChecksWidthPositivity() { Circle circle = new Circle(-1, 50); }
public void TestCirclePerimeter() { Circle circle = new Circle(1, 5); Assert.AreEqual(12, circle.Perimeter()); }
public void TestBiggerCirclePerimeter() { Circle circle = new Circle(10, 100); Assert.AreEqual(220, circle.Perimeter()); }
public void TestCircleArea() { Circle circle = new Circle(1, 5); Assert.AreEqual(5, circle.Area()); }
public void TestBiggerCircleArea() { Circle circle = new Circle(10, 100); Assert.AreEqual(1000, circle.Area()); }
static void Main(string[] args) { string _string; int _shapeType = 0; bool _boorderAdded = false; bool _colorAdded = false; bool _bold = false; IShape _circle = new Circle(); IShape _rectangle = new Rectangle(); IShape _redRectangle = null; IShape _redCircle = null; IShape _doubleArea = null; IShape _boldRectangle = null; IShape _boldCircle = null; IShape _doubleSize = null; Console.WriteLine("Do you wish to create a Circle or Rectangle"); Console.WriteLine("Type 'C' for Circle and 'R' for Rectangle "); _string = Console.ReadLine(); ///WHICH shape do { if (_string == "R") { _shapeType = 1; } else if (_string == "C") { _shapeType = 2; } else { Console.WriteLine("Please choose a real pattern"); _string = Console.ReadLine(); } } while (_string != "R" && _string != "C"); ///WISH RED BORDER OR NOT Console.WriteLine(""); Console.WriteLine("Do you wish to add a red border to your shape"); Console.WriteLine("Press 'Y' for yes or 'N' for no"); _string = Console.ReadLine(); if (_string == "Y" && _shapeType == 1) { _redRectangle = new RedShapeDecorator(_rectangle); _colorAdded = true; _redRectangle.draw(); Console.WriteLine("Default area is: {0}", _redRectangle.CalcArea()); } else if (_string == "Y" && _shapeType == 2) { _redCircle = new RedShapeDecorator(_circle); _colorAdded = true; _redCircle.draw(); Console.WriteLine("Default area is: {0}", _redCircle.CalcArea()); } else { Console.WriteLine("No red border added"); if (_shapeType == 1) { _rectangle.draw(); Console.WriteLine("Default area is: {0}", _rectangle.CalcArea()); _colorAdded = false; } else { _circle.draw(); Console.WriteLine("Default area is: {0}", _circle.CalcArea()); _colorAdded = false; } } //WISH BOLD LINES OR NOT Console.WriteLine("Do you wish to make lines bold"); Console.WriteLine("Press 'Y' for yes or 'N' for no"); _string = Console.ReadLine(); if (_string == "Y" && _shapeType == 1 && _colorAdded == true) { _boldRectangle = new BoldStyleDecorator(_redRectangle); _boldRectangle.draw(); _bold = true; Console.WriteLine("Area with bold style: {0}", _boldRectangle.CalcArea()); } else if (_string == "Y" && _shapeType == 2 && _colorAdded == true) { _boldCircle = new BoldStyleDecorator(_redCircle); _boldCircle.draw(); _bold = true; Console.WriteLine("Area with bold style: {0}", _boldCircle.CalcArea()); } else if (_string == "Y" && _shapeType == 1 && _colorAdded == false) { _boldRectangle = new BoldStyleDecorator(_rectangle); _boldRectangle.draw(); Console.WriteLine("Area with bold style: {0}", _boldRectangle.CalcArea()); _bold = true; } else if (_string == "Y" && _shapeType == 2 && _colorAdded == false) { _boldCircle = new BoldStyleDecorator(_circle); _boldCircle.draw(); Console.WriteLine("Area with bold style: {0}", _boldCircle.CalcArea()); _bold = true; } else { _bold = false; Console.WriteLine("No bold style added"); } ///increase are by two /// Console.WriteLine(""); Console.WriteLine("Do you wish to double the size Y/N"); _string = Console.ReadLine(); if (_string == "Y") { if (_shapeType == 1 && _bold == true) { Console.WriteLine(""); Console.WriteLine(""); _doubleSize = new DoubleSizeDecorator(_boldRectangle); Console.WriteLine("Area with bold style: {0}", _doubleSize.CalcArea()); } else if (_shapeType == 2 && _bold == true) { Console.WriteLine(""); Console.WriteLine(""); _doubleSize = new DoubleSizeDecorator(_boldCircle); Console.WriteLine("Area with bold style: {0}", _doubleSize.CalcArea()); } else if (_shapeType == 1 && _colorAdded == false && _bold == false) { Console.WriteLine(""); Console.WriteLine(""); _doubleSize = new DoubleSizeDecorator(_rectangle); Console.WriteLine("Area with bold style: {0}", _doubleSize.CalcArea()); } else { Console.WriteLine(""); Console.WriteLine(""); _doubleSize = new DoubleSizeDecorator(_circle); Console.WriteLine("Area with bold style: {0}", _doubleSize.CalcArea()); } } else { Console.WriteLine("Didn't increase size by two"); } }
public void TestSidesCount() { Circle circle = new Circle(1, 5); Assert.AreEqual(4, circle.SidesCount); }
/// <summary> /// Change the radius of the circle shape. /// </summary> public static void SetRadius(this Circle circle, double radius) { NativeMethods.cpCircleShapeSetRadius(circle.Handle, radius); }
/// <summary> /// Performs the data processing associated with this editing operation. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated.</param> internal override void CalculateGeometry(EditingContext ctx) { // Get the rotation & scale factor to apply. PathInfo pd = new PathInfo(this); // Go through each leg, creating the geometry for each span... // (the following is based on the logic of PathInfo.Render) // Initialize position to the start of the path. IPosition gotend = m_From; // Initial bearing is whatever the desired rotation is. double bearing = pd.RotationInRadians; double sfac = pd.ScaleFactor; for (int i = 0; i < m_Legs.Count; i++) { Leg leg = m_Legs[i]; // Include any angle specified at the start of the leg StraightLeg sLeg = (leg as StraightLeg); if (sLeg != null) { bearing = sLeg.AddStartAngle(bearing); } // Determine exit bearing for circular leg (do it now, in case an extra leg complicates matters below) double exitBearing = bearing; CircularLeg cLeg = (leg as CircularLeg); if (cLeg != null) { IPosition center, ec; double bear2bc; cLeg.GetPositions(gotend, bearing, sfac, out center, out bear2bc, out ec, out exitBearing); // The circle should have been created already, but with an undefined radius Circle circle = cLeg.Circle; Debug.Assert(circle != null); circle.Radius = cLeg.RadiusInMeters * sfac; circle.CenterPoint.ApplyPointGeometry(ctx, PointGeometry.Create(center)); } // Obtain geometry for each span and assign to attached features SpanInfo[] spans = leg.PrimaryFace.Spans; ILineGeometry[] sections = leg.GetSpanSections(gotend, bearing, sfac, spans); AttachGeometry(ctx, spans, sections); // Note the position at the end of the leg IPointGeometry legEnd = sections[sections.Length - 1].End; // If we're dealing with the first face of a staggered leg, process the second face if (leg.AlternateFace != null) { // If this is the very last leg, make sure we use the path end point (there could // conceivably be some roundoff). if (i == m_Legs.Count - 1) { legEnd = m_To.PointGeometry; } spans = leg.AlternateFace.Spans; sections = leg.GetSpanSections(gotend, legEnd, spans); AttachGeometry(ctx, spans, sections); } // Get to the end of the leg gotend = legEnd; bearing = exitBearing; } }
public void TestCircle() { Circle Figure = new Circle(10); Assert.AreEqual(Math.PI*Math.Pow(10,2), Figure.GetArea()); }
public void TestCircleConstructor() { Circle circle = new Circle(40); Assert.AreEqual(40, circle.Radius); }
public void Setup() { circle = new Circle(5); rectangle = new Rectangle(5, 10); square = new Square(5); }
/// <summary> /// Change the offset of the circle shape. /// </summary> public static void SetOffset(this Circle circle, Vect offset) { NativeMethods.cpCircleShapeSetOffset(circle.Handle, offset); }