# Vec vs Point what to use?

All this time I had been using Point(…). I recently realised there is a Vec(…) function in the GeometryBasics.jl package. Is there a particular one that I should Use?

``````julia> Point(1,2) == Vec(1,2) == [1,2]
true
``````

All Makie.jl functions that work on `Point` work on `Vec` as far as I have checked.
But for parameters of functions that accept an input of type `Point` do not accept those of type `Vec`

``````julia> f(x::Point) = x
f (generic function with 1 method)

julia> f(Point(0))
1-element Point{1, Int64} with indices SOneTo(1):
0

julia> f(Vec(0))
ERROR: MethodError: no method matching f(::Vec{1, Int64})
``````

What’s the difference except the name? There’s little to no documentation on either of them.

Which one should I use to represent Pos, Vel, Acc, etc of a particle.
Note: I am using GLMakie.jl to render everything. If I’m not wrong, Makie uses `Point` internally to represent positions. There’s also more usage of `Point` in Makie.jl docs although that doesn’t matter much.

Conceptually, I feel a `Vector` represents Position, Velocity, etc in a more semantic way.
Which one should I use?

GeometryBasics is not very principled with these, they are mostly needed just as storage of three numbers with scalar semantics. For most purposes in Makie they’ll work the same way

“Most”…? any one that you’d prefer btw?

Different software tools sometimes use different conventions for vectors vs points. Semantically, though … A point is defined as a location with no extent, so to me it makes sense to use then name when representing absolute coordinates or position in some space. A vector is defined by magnitude and direction, so it makes sense for many quantities like velocity and acceleration. That being said… they’re often represented with the same underlying structure, e.g. a vector in \Re^n, and you can also think of a spatial coordinate in terms of a vector rooted at the origin of a space, so the terms are sometimes used interchangeably.

tl;dr: read the docs for the specific tools you’re using and play along with however they interpret points and vectors.

1 Like

I don’t know about Makie, but imo, points and vectors are different, even though they can be represented the same way. You cannot meaningfully add two points, for example, but you can add a vector to a point to get a new point. You can also subtract two points to get a vector.

In homogeneous coordinates, a 3d point is represented as `[x, y, z, 1]` and a 3d vector as `[x, y, z, 0]`.

You can move a point, but not a vector. You can scale a vector, but not a point.

I mean the definition of Vectors and Points is something contextual and Philosophical too. Both can be defined in the same way. I like to think of Vectors as a set of data points. Not just magnitude and direction but any data from any number of dimensions.

Conceptually, at least to me, Vectors feel more wide-spread in use when it comes to Mathematics, Physics and Computers.

But yes, that is different from the way things work in Julia and specifically the way it works in GLMakie… the primary package I’m using for my project.

Vectors, geometrically can represent a Point in space as well as directions between to Points in space.

Intuition aside, I just wanna know what I should use for computations. There seems to be very little documentation about it anywhere. Things are pretty much interchangeably used, although I’m not quite sure.

1 Like

I’d rather argue Points are Rigid. You can traverse through different points and change the `Position` of objects by traversing through Vectors.

But yes, that’s again just abstract Ideas. It all depends on how one feels and things about something very subjective.

That aside, I’d like to know what I should use purely for computational purposes. Is there a drawback to use one over the other in Makie? or somewhere else in Julia?

It is common to represent points in terms of vectors, but that’s really just an example of what I was saying: To start with an origin, which is a point, and add a vector, to get the final point.

While it is convenient to calculate with both points and vectors as a collection of numbers, I would argue that from a geometrical standpoint they are fundamentally different, and that the “direction and magnitude” is the right way of seeing a vector, even though you can represent a vector in a particular basis as a sequence of numbers. Keep in mind that a vector can have infinitely many representations depending on the basis, but the ‘underlying reality’, as far as mathematics are ‘real’, is a direction and a magnitude.

The same applies for points, the location of the middle of your computer monitor is independent of whether you represent it with respect to an origin at the lower left corner of your screen, your office door, or in longitude-latitude coordinates.

You can have ‘direction and magnitude’ in arbitrarily high dimensions, there’s no limitation to 3d space.

`Point` and `Vec` were carefully designed in Meshes.jl for geometrical work. I strongly recommend using a mathematically-driven definition. Notice that you also have the concept of `coords` in a given coordinate reference system (`CRS`), which is a 3rd different concept that we also have there.

Meshes.jl functions do not work the same way as GLMakie.jl and GeometryBasics.jl which are actually my use cases.

It did provide me with better documentation making it clearer what `Vectors` and `Points` are for. But again, that is very contextual. I would like to know if they hold the same meaning and use in GLMakie.jl

I did find out 1 case in which `Vec` can not be used in place of `Point`. i.e. `arrows([tail], [direction])`

one can use Points for either one of those but Vectors don’t work for tails.

I wonder what other instances these constraints pop up. I don’t want to be very inconsistent with things so would not plan to switch between the two for different scenarios.

I do feel at least for Makie.jl, Points are more widely accepted as a type than Vec.
I would like to know more about it though.

I wonder if there’s a difference in meaning between `arrows(p0::Point, v::Vec)` and `arrows(p0::Point, p1::Point)`. My intuition tells me that the former should be an arrow starting at `p0` and pointing to `p0 + v`, and the latter should start at `p0` and point to `p1`, that would agree with my description of the difference between point and vector. Is this the case?

Nope. I thought as too!

However, `arrows(p0::Point, v::Vec)` & `arrows(p0::Point, p1::Point)` both output the same result as `p0 + v`.

It isn’t so intuitively pleasing to me either. But turns out much of Makie.jl has `Point` type as a substitute for `Vec` but not the other way round.

I’ll just use Points now.

Created my first animation btw! Yayyy!

2 Likes

So you mean the latter creates an arrow from `p0` to `p0 + p1`? That is unfortunate.

yep, it is. I would have expected it to create an arrow starting out at `p1` with a direction `p2-p1`. i.e. start at `p1` and end at `p2`. But hey! Works for me. I’ll just use Points. They’re nice and sweet.
(although it would have been more pleasing for me to be able to do everything through `Vec`… to me that has a wider span of use/definition)

Worth sharing a picture:

``````using Meshes

import GLMakie as Mke

viz(Point(1, 1), color="black")
viz!(Vec(1, 1), color="red")
viz!(Ray((1, 1), (1, 1)), color="blue")
``````

These examples assume `Cartesian` coordinates.

Yes, I completely agree that this should have been the case.

But it is rather unfortunate that this ISN’T the case with GLMakie.jl, which is precisely what I am using (and Not Meshes.jl).

So I’ll have to stick with using `Point` as some kind of Vector for all practical purposes.