5
$\begingroup$

I am trying to center text on an arc by taking the mean value of the arc vertex positions and offsetting the position of text vertices with this value. But this doesn't seem to be working. What's going wrong? enter image description here

$\endgroup$

1 Answer 1

8
$\begingroup$

Before I get to the solution, this is just to show you what is going wrong with your setup: you have an Arc with Resolution of 16, that makes 17 points (including the origin point), and their positions are the cosine for X, sine for Y and Z is 0 for all of them.

Now you are plugging their Position values (a field of 17 vectors with 3 values each) into a Float input and calculate the Mean, which results in the Attribute Statistic node calculating the average value of 51 float values.

points and average

This single average float value of about 0.398 you then plug into the Offset input of the Set Position node, which expects vectors. Feeding it a single float results in using this value for X, Y and Z and so placing your text at (0.398, 0.398, 0.398). In your top view screenshot it looks like it's just misplaced in X and Y, but it's also placed above the arc:

offset

So to calculate the center of the area enclosed by the Arc (which is what I suppose you tried to achieve) you first of all have to choose Vector in the Attribute Statistic node. If you leave the Domain at Point you will end up having the text placed close to the curve on the right, since there are much more points than the only one to the left.

The same will occur if you choose Edge, what you need is Face. In order to make this work you have to plug a Fill Curve node after the Arc node. There are two settings: N-gons will get you the same result as Point or Edge, but Triangles will place it correctly.

You can compare this with setting the origin of a mesh object. If you right-click on it and go to Set Origin there are (among others) the options Origin to Center of Mass (Surface) and Origin to Center of Mass (Volume). In the image below you see an orange outline, this is a mesh object in the shape of the Arc with the same number of vertices.

Choosing Origin to Center of Mass (Surface) sets the origin where the calculated Mean is with the Triangles option in the Fill Curve node, but using N-gons the Mean is where the Origin to Center of Mass (Volume) would be set and it is the same place you'll get with the Point option. (By the way, although it's still in my screenshot - since you don't want to move separate points of the text curve, a Realize Instances node is not needed).

center of mass surface vs volume

The only problem that's left is this might not really look correctly placed - when you look at the orange origin points in the above image, the character "a" seems a bit off-center, and comparing to uppercase "H" or "O" you can see it's not only because it's lowercase. Since fonts have so called ascenders and descenders, the center of a character is often not the visible center of its geometry.

To get the center of the character's geometry you can plug it into a Bounding Box node (after Realizing Instances) and calculate the Mean like you do with the Arc. Then subtract the character's Mean from the Arc's Mean and use this as _Offset for the Set Position node:

bounding box offset

This results in better placed characters as you can see below. You can use either the Bounding Box as I showed in the nodetree above or the Convex Hull node. For very symmetrical letters like the uppercase "H" and "O" it won't make a difference, however if you have an asymmetrical letter like the lowercase "a" it will slightly differ.

bounding box centered

At last here is a comparison with the character "a" and using Bounding Box vs. Convex Hull. As you can see, there is a very subtle difference and it might not matter much, however with other characters or even words instead of single characters it might look different. I guess it's mostly dependent on the shapes and an aesthetical decision based on your preferences which one you choose, I just wanted to show you the options.

bounding box vs convex hull

$\endgroup$
7
  • 1
    $\begingroup$ Thank you very much for such a detailed explanation! $\endgroup$ Commented Dec 7, 2022 at 11:31
  • 1
    $\begingroup$ @LomaHarshana The only problem here is that font characters usually don't have their center in the center of the actual curve that builds the letter. If you took a small circle for example and would place it with this setup inside the arc, you will see that the letters are slightly offset from this. To place a character centered according to its geometry you have to use a Bounding Box or Convex Hull node. I will edit my answer to show this. $\endgroup$ Commented Dec 7, 2022 at 14:59
  • 1
    $\begingroup$ Such a good answer. Mine was based on 'largest circle that can be inscribed'... but too complicated for this case. $\endgroup$
    – Robin Betts
    Commented Dec 7, 2022 at 20:15
  • 1
    $\begingroup$ @GordonBrinkmann Thanks again! $\endgroup$ Commented Dec 10, 2022 at 5:10
  • 1
    $\begingroup$ @GordonBrinkmann I have a quick side question, if you don't mind (please ignore it if it doesn't make sense). In your first illustration, where you have shown the arc vertices and their angles, how did you add the angle values for so many vertices with correct alignment? $\endgroup$ Commented Dec 10, 2022 at 5:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .