# You Good at Vectors?

**URL:** https://forum.kirupa.com/t/you-good-at-vectors/262928
**Category:** programming
**Created:** [June 11, 2008, 6:38am UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928 "2008-06-11T06:38:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![motionsmith](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@motionsmith](https://forum.kirupa.com/u/motionsmith)
#### Post date: [June 11, 2008, 6:38am UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/1 "2008-06-11T06:38:52Z")

</div>

I got this project. I’m working with rotated rectangles a lot. I’m drawing them (using the graphics API) so that their X and Y are centered withing the rectangle.

I’m often needing to figure out these regtangles’ corner coordinates. I’d like to make some getters that spit out the coordinates of a corner such as

```auto
num = rect.upperLeft

```

. Anyone have the Vector skills to show me the pattern to getting these values? I’m decent with vectors, but apparently not good enough. My Vector class has functions to set angle, length, rotate(), plus, minus, normal, etc, so feel free to use those in your example.

Thanks,  
Eric

---

<div class="post-metadata">

### Author: ![Sirisian](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@Sirisian](https://forum.kirupa.com/u/Sirisian)
#### Post date: [June 11, 2008, 12:30pm UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/2 "2008-06-11T12:30:47Z")

</div>

Use a matrix to transform the points.

if you have the points  
(-10,-10), (10,-10), (10,10),(-10,10)  
then to get the points you apply a matrix to it that has the transformation  
translate(rotationPointX, rotationPointY); //not really needed if you declare the points around the (0,0)  
rotate(angleInRadians);  
translate(posX, posY);

Flash has a Matrix class in flash.geom.Matrix;

---

<div class="post-metadata">

### Author: ![DiamondDog](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@DiamondDog](https://forum.kirupa.com/u/DiamondDog)
#### Post date: [June 11, 2008, 12:49pm UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/3 "2008-06-11T12:49:43Z")

</div>

(sorry - posting in the wrong thread - oops)

---

<div class="post-metadata">

### Author: ![substance](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@substance](https://forum.kirupa.com/u/substance)
#### Post date: [June 11, 2008, 5:58pm UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/4 "2008-06-11T17:58:06Z")

</div>

Check out

[http://cheezeworld.com/actionscript-3-math-classes-for-game-developers/](http://cheezeworld.com/actionscript-3-math-classes-for-game-developers/)

---

<div class="post-metadata">

### Author: ![motionsmith](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@motionsmith](https://forum.kirupa.com/u/motionsmith)
#### Post date: [June 12, 2008, 4:52am UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/5 "2008-06-12T04:52:51Z")

</div>

Thanks Sirisian, I’ve applied the usage that you gave me, but I don’t see any explanation of how to retrieve the corner points of a rotated rectangle. It seems that you showed me how to rotate it (and translate it) but not how to get coordiantes for corners (unless I’m missing something).

The code here occurs every time the mouse is clicked and dragged. The point at which it is clicked gives us the \_startPoint Vector. Using the difference between the the mouse’s start point and it’s current point will give me the length and rotation of the rectangle (The height is fixed). The rectangle is named “\_lov”.

```auto

private function onMouseMove(event:MouseEvent):void
		{
                        //create the object the first time the mouse moves
			if (!_lov)
			{
				_lov = new LevelObjectView();
				levelView.addChild(_lov);
				_lov.explicitHeight = 10;
			}
			var distance:Vector = new Vector(levelView.mouseX - _startPoint.x, levelView.mouseY - _startPoint.y);
			_lov.explicitWidth = distance.length;
			var matrix:Matrix = new Matrix();
			matrix.rotate(distance.angle);
			//below here is all code for setting the x, y location of the rotate object.
			var center:Vector = _startPoint.plus(distance.scale(.5));
			var vectToCenter:Vector = distance.normal;
			vectToCenter.length = _lov.explicitHeight / 2;
			center.plusEquals(vectToCenter);
			matrix.translate(center.x, center.y);
			_lov.transform.matrix = matrix;
		}

```

What I’d like to do is be able to access that rectangle’s corner points any time. All the info that I have about it is its explicit width, height, x, y, and rotation.

Any help would be GREATLY appreciated. Thanks,

Eric

---

<div class="post-metadata">

### Author: ![motionsmith](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@motionsmith](https://forum.kirupa.com/u/motionsmith)
#### Post date: [June 12, 2008, 5:26am UTC](https://forum.kirupa.com/t/you-good-at-vectors/262928/6 "2008-06-12T05:26:14Z")

</div>

I figured out something that works. Let me know if there’s a better way:

```auto

var point:Point = transform.matrix.transformPoint(new Point(-explicitWidth / 2, explicitHeight / 2));

```

However the strange thing is that if I try to access this value every mouse move, the very first two times that it traces out (after the matrix has been made and assigned to the object’s tranform property), I get this strange value:

[-107374182.4, -107374187.4]

Any clue why? Thanks.
