none
C# MATH RRS feed

  • Question

  • I'm trying to make an object to follow my mouse I think I'm doing good but I have a little problem 

    public void main()
            {
                try
                {
                    // main loop ,drawing from first point to the mouse 
                    rX = MousePosition.X; rY = MousePosition.Y;
    
    
                    Graphics graphicsObj;
    
                    graphicsObj = this.CreateGraphics();
                    Pen myPen = new Pen(Color.BlueViolet, 3);
    
                    Point point = new Point(mX, mY);
    
                    Rectangle myRectangle = new Rectangle(X, Convert.ToInt16(Y), 50, 50);
                    graphicsObj.Clear(Color.White);
    
                    mX = myRectangle.X;
                    mY = myRectangle.Y;
                    Y = (X - mX) * ((mY - rY) / (mX - rX)) + mY;
                   
    
                    graphicsObj.DrawEllipse(myPen, myRectangle);
    
                    //myRectangle.Location = new Point(X, (X - mX) * ((mY - rY) / (mX - rX)) + mY);
                    label1.Text = "( " + X + " , " + Y + " )" + "( " + rX + " , " + rY + " )";
                }
                catch
                {
    
                }
                finally
                {
    
                }
                
                
            }

    when I tried to find out why the ellipse didn't move in Y-axis I found that Y always zero, can anyone tell me why its equal zero, I have tried the equation many times in paper and it is true but I don't know why it is zero

    Wednesday, January 22, 2020 11:30 PM

All replies

  • You are creating myRectangle at X and Y, then setting mX to myRectangle.X.

    This means that X and mX will be the same, so (X - mX) will always be zero.

    Thursday, January 23, 2020 12:47 AM