# Calculating top-left point from center point and mouse pointer location

I'm making a paint program for my collage project. What I want to do is this S is a center point that is constant A,B,C,D - one of this is one of mouse location. Normally I click on point A then drag it to point C and a square will be created with start point A and width (C.X-A.X) and height (C.Y-A.Y). But I need it when I click on point S and drag it to Point C it should create a square with Point A as start point, width and height. All of those I need to calculate from Center point S and one point (c for example). This is the code that I have

Rectangle(

(int)Math.Min(center.X, mouse.X) - Math.Abs(mouse.X - center.X), (point A.X)

(int)Math.Min(center.Y, mouse.Y) - Math.Abs(mouse.Y - center.Y), (point A.Y)

(int)Math.Abs(endPoint.X - startPoint.X) * 2, (width)

(int)Math.Abs(endPoint.Y - startPoint.Y) * 2)); (height)

This works if I go from S to C, but when I go, for example, from point S to point A than point C of the square stays in place while point S and A(double the length from S to C) moves.

I hope You understand me. :D

• I don't believe this involves linear programming... Apr 5 '15 at 0:06
• I'm sorry. I have removed the tag. Apr 5 '15 at 0:10

I was able to figure it out.

Rectangle(

(int)Math.Min(center.X, mouse.X) - Math.Abs(mouse.X - Math.Min(center.X,mouse.X));, (point A.X)

(int)Math.Min(center.Y, mouse.Y) - Math.Abs(mouse.Y - Math.Min(center.Y,mouse.Y), (point A.Y)

(int)Math.Abs(endPoint.X - startPoint.X) * 2, (width)

(int)Math.Abs(endPoint.Y - startPoint.Y) * 2)); (height)

I think this is the best solution. If You have a better one feel free to post it. Thank You