Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a CGVector?

After searching the documentation, I still cannot find a reasonable explanation for what a CGVector is. The only times it is mentioned in the documentation is when it shows what its typedef is.

struct CGVector {
   CGFloat dx;
   CGFloat dy;
};
typedef struct CGVector CGVector;

From basic geometry I know that dx means delta x, or change in x. The same goes for dy. With this knowledge, what is a CGVector (or just any kind of vector) from a programming standpoint? If it helps, I am trying to understand a vector in the context of SpriteKit's SKPhysicsBody and velocity.

like image 421
Brian Tracy Avatar asked May 03 '14 04:05

Brian Tracy


People also ask

What is a CGSize?

Overview. A CGSize structure is sometimes used to represent a distance vector, rather than a physical size. As a vector, its values can be negative. To normalize a CGRect structure so that its size is represented by positive values, call the CGRectStandardize(_:) function.

What is CGRect origin?

In the default Core Graphics coordinate space, the origin is located in the lower-left corner of the rectangle and the rectangle extends towards the upper-right corner.


1 Answers

As you mentioned, dx and dy represent change in x and change in y, respectively. That makes it a good candidate to represent the velocity of an object in two dimensions.

like image 86
Zach Langley Avatar answered Oct 26 '22 18:10

Zach Langley