Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi. i need some codes about 2 square and the accidents that they have with each other.first of all, i need to have codes about a class for point and line. then with ''if'' method i should combine two square with each other and understand the position of the accident's points.
Posted
Updated 31-Dec-12 6:27am
v2
Comments
OriginalGriff 31-Dec-12 12:18pm    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
keivan ahmadian 31-Dec-12 12:23pm    
first of all, i need to have code about a class for point and line. then i should combine two square with each other and understand the position of the accident's points.

I believe what you are referring to is called "Collision Detection".

This[^] small tutorial from MSDN may help you along your way.

I also found this question in Q&A you can refer to: how to analyze whether a rectangle is overlap another rectangle[^]
 
Share this answer
 
v2
Comments
keivan ahmadian 31-Dec-12 12:34pm    
yes, its exactly "Collision Detection". but i dont want grafically. i need the code. imagin 2 square in the space. show their position they have with each other.
fjdiewornncalwe 31-Dec-12 12:43pm    
Collision detection is never done graphically. Graphics are only employed to give a simple visual to the user of the underlying calculation.
keivan ahmadian 9-Jan-13 14:26pm    
what is the formula of collision detection in windows app form in c# ?
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Square_Point_Line
{
    public class Point
    {
        public Point()
        {

        }

        public Point(double x,double y)
        {
            this.X = x;

            this.Y = y;
        }
        public double X { get; set; }

        public double Y { get; set; }


        /// <summary>
        /// This Function Shows the Coordinates of the Point
        /// </summary>
        public void ShowPoint()
        {
            Console.WriteLine("\t\n [x={0},y={1}]",X,Y);
        }
    }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Square_Point_Line
{
 
    public class Line
    {

        public Line()
        {

        }

        public Line(Point a,Point b)
        {
            this.A = a;

            this.B = b;

        }

        public double Length
        {
            get
            {
                 return Math.Sqrt(Math.Pow(A.X - B.X, 2) + Math.Pow(A.Y - B.Y, 2));
            }
        }

        public Point A { get; set; }

        public Point B { get; set; }


        /// <summary>
        /// This Function Shows the Length of Line
        /// </summary>
        public void DisplayLine()
        {
            Console.WriteLine("LengthOfLine={0}",this.Length);
        }
    }
}



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Square_Point_Line
{
    public class Square
    {
        public Square()
        {

        }
        public Square(Line ab,Line bc,Line cd,Line da)
        {
            this.AB = this.BC = this.CD = this.DA = ab;
        }

        public Square(Point a,Point b,Point c,Point d)
        {
            this.A = a;
            this.B = b;
            this.C = c;
            this.D = d;
        }
        public Line AB { get; set; }
        public Line BC { get; set; }
        public Line CD { get; set; }
        public Line DA { get; set; }

        public Point A { get; set; }
        public Point B { get; set; }
        public Point C { get; set; }
        public Point D { get; set; } 
   
    }
}

}
 
Share this answer
 
Comments
keivan ahmadian 1-Jan-13 9:40am    
thank you. are these codes complete or they are a part of this project?
keivan ahmadian 1-Jan-13 10:08am    
ye soal mohandes jan. ina ro tooye botton bezaram ya ye textbox dorost konam?? age mishe lotf konid file zip ro baram email konid. keivankeivan90@yahoo.com
thank you very much.
Behno0o0oD 1-Jan-13 10:51am    
bebin ina 3 ta classe k man zire ham avordam inja, aval noghte ast, bad khatte, bad mshe square, doone doone class besaz,injoori behtar mshe ravande barnamat,bad hala mtuni too layeye presentation (hamoon programe khodemoon) vaghti noghteharo midi va bad lineha sakhte mshan va bad square ha ro tolid mkoni befahmi k aya ina tadakhol daran ba ham ya nadaran ;)faghat kafie bakhshe nahayi ro khodet benvisi
Behno0o0oD 1-Jan-13 10:53am    
ini k man neveshtam noktash ine k har class mtune yek noe dadeyi bashe ;);)
Behno0o0oD 1-Jan-13 11:05am    
ina k man neveshtam roo console hastesh, man form kar nakardam hanooz, barat mifrestam, bebin, baghish ba khodet ;)

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