1
$\begingroup$

I'm making a paint program for my collage project. What I want to do is this

enter image description here

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

Thank You in advance.

$\endgroup$
2
  • $\begingroup$ I don't believe this involves linear programming... $\endgroup$
    – Math1000
    Apr 5 '15 at 0:06
  • $\begingroup$ I'm sorry. I have removed the tag. $\endgroup$ Apr 5 '15 at 0:10
0
$\begingroup$

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.