Login

Fancade Wiki

Renamed Setting the geometric position of an object to Getting the geometric position of an object

... ...
@@ -206,3 +206,5 @@ Script/How do I get\/set the geometrical position of an object%3F.md: Script/How
206 206
I get\/How do I get or set the geometrical position of an object?.md
207 207
Script/How do I get\/How do I get or set the geometrical position of an object?.md: Script/How
208 208
do I get or set the geometrical position of an object?.md
209
Script/Setting the geometric position of an object.md: Script/Getting the geometric
210
position of an object.md
... ...
@@ -0,0 +1,19 @@
1
When you get the position of an object, you actually get the position of the object's *center of mass*.
2
3
[[/uploads/center of mass opaque.png]]
4
5
In most cases, this is enough, as the center of mass of an object usually corresponds to its geometric center (or centroid). However, in cases where they do not align, and you wish to get the geometric center, getting its position will thus not suffice.
6
7
The center of mass of an object is **not** the same as it's geometric position. The *geometric position* of an object is the midpoint of the vector between it's minimum and maximum vectors, and is the actual center of an object, which doesn't always correspond to the center of mass of the object.
8
9
The trick is to take the [[Get Position]] vector and **offset it by half the total size of the object**. The "total size" of the object refers to the sum of the minimum and maximum vectors of the object.
10
11
[[/uploads/geometrical position opaque.png]]
12
13
By extension, to *set* the geometric position of the object, set the position (center of mass) of the object to the desired position (centroid) subtracted by the offset.
14
15
[[/uploads/set geometrical position opaque.png]]
16
17
In the example above, the [[Get Size]] block returns the minimum and maximum vectors. These are added together, and the result is halved and stored for later in the variable `Offset`.
18
In the next section, the object pointed to by `Obj` is set to the desired geometric position (`(1,1,1)`) subtracted by `Offset`.
19
In the section after, the object's new position is then queried, and added to the offset to produce the geometric position of the object.
... ...
\ No newline at end of file
... ...
@@ -1,19 +0,0 @@
1
When you get the position of an object, you actually get the position of the object's *center of mass*.
2
3
[[/uploads/center of mass opaque.png]]
4
5
In most cases, this is enough, as the center of mass of an object usually corresponds to its geometric center (or centroid). However, in cases where they do not align, and you wish to get the geometric center, getting its position will thus not suffice.
6
7
The center of mass of an object is **not** the same as it's geometric position. The *geometric position* of an object is the midpoint of the vector between it's minimum and maximum vectors, and is the actual center of an object, which doesn't always correspond to the center of mass of the object.
8
9
The trick is to take the [[Get Position]] vector and **offset it by half the total size of the object**. The "total size" of the object refers to the sum of the minimum and maximum vectors of the object.
10
11
[[/uploads/geometrical position opaque.png]]
12
13
By extension, to *set* the geometric position of the object, set the position (center of mass) of the object to the desired position (centroid) subtracted by the offset.
14
15
[[/uploads/set geometrical position opaque.png]]
16
17
In the example above, the [[Get Size]] block returns the minimum and maximum vectors. These are added together, and the result is halved and stored for later in the variable `Offset`.
18
In the next section, the object pointed to by `Obj` is set to the desired geometric position (`(1,1,1)`) subtracted by `Offset`.
19
In the section after, the object's new position is then queried, and added to the offset to produce the geometric position of the object.
... ...
\ No newline at end of file
Fancade Wiki