Monday, 30 March 2020

Calculating area enclosed by intersections

A small math question today.

Given a unit sphere and an arbitrary ellipsoid, calculate the surface area of sphere inside the ellipsoid.

Without loss of generality, we may assume the unit sphere to be centered at origin, then the question depends solely on the 6 parameters defining the ellipsoid, $c_i, \alpha_i$ for $i=1,2,3$ in $\sum (x_i-c_i)^2/\alpha _i ^2 = 1$. Without thinking too much about existence of analytic solution in terms of the parameters, we want to look for ways to calculate or at least approximate the problem.

My own solution is based on the famous Gauss-Bonnet theorem:
$\int _M KdA + \int _{\partial M} \kappa _g ds = 2\pi \chi (M)$

The curvature of a unit sphere is constantly 1, and the Euler characteristic of a disc is 1. As long as you can calculate the geodesic curvature you get
$|M| = 2\pi - \int _{\partial M} \kappa _g ds$.
The intersection is a union of finitely many closed curves we can just calculate one by one.

A simple example would be as follows:

Consider the intersection between $x^2+y^2+z^2=1$ and $(x-1)^2+y^2+z^2=1$. The intersection $\Gamma$ is given by $x = \frac{1}{2}$ and $y^2+z^2 = \frac{3}{4}$. This is a circle of radius $\frac{\sqrt{3}}{2}$ with geodesic curvature $\frac{1}{\sqrt{3}}$. Therefore we have $\int _{\Gamma} \kappa _g ds = \pi$, so $|A| = 2\pi \pm \pi$ depending on the orientation. The surface area can be verified using the formula from Archimedes $|A| = \pi (h^2+a^2)$.


Of course, obtaining the parametrization is sometimes too difficult. Are there any easier ways to approximate the answer? Here are two suggestions from my friends.

- Monte Carlo based: sample points on the surface of the sphere and check whether it is in the ellipsoid.

- Integral approximation: similar to Monte Carlo but instead we split the sphere into pieces using spherical coordinates, then the required area is the integral over the indicator function of the ellipsoid.

And of course we can get an estimation using the Gauss-Bonnet approach. Let us call the sphere $S$ and the ellipsoid $E$. We start from a point of intersection, say $x$. The curve goes in the direction $v\in T_xS \cap T_xE$, the intersection of the tangent spaces of the two objects at $x$. We know the intersection must be of dimension 1 because if the two objects are cotangent at the point then the intersection is a point which generates no area after all.

Obtaining this direction is simply algebra, where we find the intersection between two subspace. With this direction we can numerically obtain a closed curve. There is a gap here because we may not go back to the starting point using numerical approximation. We just assume by smoothness (well sphere and ellipsoid are very nice objects) by doing fine enough approximation things would work (actually I believe we can prove this but I am not an expert in numerical methods) -- then we have an approximated curve of intersection.

From here we can calculate its length as well as its geodesic curvature, and the estimated area follows.

Gauss-Bonnet seems quite universal even if we generalize sphere and ellipsoid to other bounded closed $C^{\infty}$ objects because they are manifolds anyway. The only worry being whether we can get a closed curve without any global features that promises convergence.


Well this is just a funny little problem that I enjoyed during the lockdown. I feel like I should write some maths before I go back to my creation whether it is literature, music or research.

Meanwhile I hope everyone is alright during the pandemic -- whether you call it COVID-19, or Wuhan virus. Stay indoor, and stay healthy.

Monday, 9 March 2020

⑨/3/2020 Cirno's ⑨th Anniversary







YuFu - Holy Moon是自己進入太鼓界的鑰匙,做出自己最高水準似乎理所當然。


然後是IOSYS的算術教室。在東方大舉進攻音遊的世代,這首歌只是眾多東方音遊曲之一,甚至不在最熱門之列。論熱度IOSYS本身的魔理沙大盜、昆布與Usatei都在算術教室之上;其他團如Silver Forest、EastNewSound、Sound Holic等同時也有不少經典大作。除去James鬼畜圖和數學這兩個因素之外實在很難找到我對這張圖特別滿意的原因。是梗嗎?當年我還沒涉足東方,也聽不懂日文呢。


Cirno's Perfect Math Class [Wmf's Taiko]



上面那張是在11年2月5日ranked,⑨年後的2020正是做算術教室⑨週年的好時機。但⑨年後的我,做譜風格早已被「污染」:難度通漲所引致主流風格的偏移、1/6以上的混用、K社音遊的亂來風格等,潛移默化地成為了自己一部分。當我想用自己現有風格造出相近的效果時卻發現自己怎也再寫不出那種感覺。明明連打的紅藍轉換不再限於1/2拍上,自己卻發現dkkdk kkkdd這類連打放哪都不對;明明大家對串圖的接受程度比以前更高,我的成品卻比以前少了快150個音符。


不論如何,這張⑨週年版的譜面即使沒達到我心中的水準[8.5/10],要拿個不錯的分數還是可以的。我會給目前的成品7到7.5分吧。圖包等Guest diff到齊以後就會一併上傳。

Cirno's Perfect Maths Class: The 9th Anniversary Edition [Wmf's 2011 Taiko]

說句題外話,C97的高質量原創音樂其實不少。但因為它們不屬於東方或其他主流同人,外人接觸它們的機會比較少。在這裡我力推古典歌劇風的love solfege,主唱綾野えいり的歌劇腔與意大利人都對她讚譽有加:

Sunday, 16 February 2020

On three houses (3): Cindered Shadows

DLC 4 is the last scheduled expansion of Three Houses and is also the largest expansion. A completely new side story alongside with new characters, quests and activities that provides further clues about the main story.

Having new characters and activities means you need to play side story plus a complete rundown in the main story to experience everything -- which is too much for a player who have already completed the game 5 times. Below are my thoughts after completing the side story with a taste of main story with the presence of the new contents.

Part I: on game mechanics

Part II: maddening and more

*spoilers alert*

Side story

Did it in hard classic and it does not disappoint me. Enemies have config slightly above the "main story" hard, but with limited resources (though not "lacking resources") and being inaccessible to auxiliary battles it could be pretty hard. The way the game works here is pretty close to that in classic Fire Emblem (like Blazing Blade), so as the difficulty.

The side story consists of 6 unique battles. Enemies are compactly packed that does not allow the slightest bit of excessive training.

I personally like the third battle the most -- the two possible routes gives flexibility on how you can play the stage. Actually I figured that it is the safest to use both of them.

The final boss is also interesting given its gimmicky special attack. I found however, the fight would still be possible without the post-AOE weakening. That would be a lot more interesting as well as pushing the difficulty up to the maddening bar.

Story-wise, there is not a lot that you can do in a 7 chapter span where the second half are all about consecutive battles. Someone data-mined that there will be 13 chapters and a more detailed stories can be delivered in such length.

With the introduction of Abyss, I expect them to focus on interaction among underground students and residents because those residents are reasons the student were there. But with 7 chapters only IS did enough to introduce the students. The interactions are left for support conversations, which are also nicely written.

New classes

Yes that is a great solution to what I pointed out before. The new classes aimed to provide full flexibility between magic accessibility and melee potential of the characters.

Dark fliers is the long awaited class, fliers that can use magic. Even with sacrificed growth the class completely worth it given how overpowered fliers can be in the game.

Valkyries seem to clash with holy/dark knight at the master class, but it bridges well between the mage class and the magic knight classes since the lance requirement is gone. It's range+1 also allows long range magic snipers other than Lorenz.

Tricksters and war monks are adjustments to melee-magical units without the problem of mortal servants where growth were split 50/50 that doesn't really work on characters that fit. These two classes are primarily for melee based (trickster for dex based and war monk for vit/def based) characters who also wants to use heal at times.

Trickster is also a bridge between sword users and mortal servants, if one trains reason and faith simultaneously. However this is really a class taylor made for Yuri with his growth distribution especially with his unique combat art, the foul play. In side story I would made him MVP as he and Edelgard combined are capable to take all physical attacks. And while Edelgard slashes back for 35 damage, Yuri simply goes for 15+45 critical...

In side story, the two magical units are very fragile due to its limited movement (compared to master classes), the abundance of stairs (for valkyries) and team composition that couldn't protect them well. The war monk is kind of balanced -- he can sweep but you do not want to put him up front too often. Yuri of course survives anywhere on the map.

If we are to use these classes in the main story with proper team setup, it is expected that dark fliers will be used as a final form. Valkyrie might be a bridge to magic knight but it may also be used as a final form if one wants to do long range snips. Trickster is probably reserved for Yuri or at most Felix. War still awkward for me.

New region and activities

That I do not have full experience of. But new area's new area. They fill the area with new NPCs and new dialogues that consolidates the story further and this is never a bad thing.

Scraps may be useful for maddening or players who really lack resources. Altar is useful for New Game+ players who wants to get specific item where they didn't get because they skipped some game elements, and that's also good.

The idea of mysterious teacher is nice although I still haven't got a full picture on how it works, but it looks interesting. And for the rest, I am probably won't have the time to explore since it will take me another 15-20 hours to go through the game again...

Cindered Shadows

4 new well-crafted characters and they fit well in Abyss.

Hapi the anti-social who disbeliefs the church. Constance a fallen noble with Schizophrenia. Balthus the bold, the gambler and the alcoholic. Though nothing too surprising you have got to say these settings do work.

And of course Yuri. As a house leader (kind of) he completes the weapon cycle among the leaders, and he also completes the personality quadrants among them. He is charismatic but disbeliefs in the church unlike Claude. His charm and wise fits with his trickster class, but what surrounds him does not give him free will after all. He is the classic Japanese RPG protagonist, and a fitting last piece to this Fire Emblem sequel.

I wish that the support between Yuri and Byleth(s) could have been more romantic -- Yuri can flirt Ingrid without backfiring (just look at Sylvain), but he seems to be so clueless against us...


So, what should I grade Fire Emblem Three Houses for now?

School system that attracts everyone except hardcore classic players. New class system that is pretty much complete upon DLC. Multiple difficulties that can be completed with or without extra battles. Up to 40 characters with thousands of support conversations.

...all in one game. This is Fire Emblem Three Houses.

I would give 7.8/10 after writing (1). But with DLC the game probably worths a score of 8.5/10. A masterpiece that is for everybody, whether you are hardcore SRPG player or not.

Tuesday, 11 February 2020

夢.十夜 (X4) Encore



此刻的我正坐在南4館的攤檔上當吉祥物兼攤主。正確來說,我現在正穿著深藍色軍裝飾演著幻影異聞錄♯FE蒼井樹(Aoi Itsuki),在她的攤檔裡幫忙。攤裡擺著新刊[火紋英雄:利用深度學習量化移位輔助技的價值]、既刊[火紋英雄:亂數機制在回合制棋盤上的優劣]和一本寄賣火紋風花雪月的狼師x青獅班級同人本。


另一方面新刊的人氣好像沒有預期中好。本來我以為遊戲邁進第三年的話老玩家陸續合出自己的+10初代(1st gen)角,在初代角合滿+10在能力(BST)值上也打不過四代(4th gen)角的情況下,移位技能應該變得更重要才對。將移位技能量化一下的話不就能知道自己的+10角色能在主流活多久了嗎?我坐了快半天才想通背後的原因。





















既刊還剩五本、新刊還有十二三本、青獅本剛好賣光。以學術本來說這次的成績也還不錯,就算現在收攤將所有本本帶回家也不會造成太大的負擔。要不乾脆找遠一點的學術攤搭訕順便把多出來的的本本送出去呢?但是這種內容不一定對到純學術攤檔的口味,唯一內容比較接近、出Q(quantum) M(machine) L(learning)本的攤檔也已經打過招呼了。







「沒有呢,這種JK服太常見了。我只是拿舊cos服循環再用一下啦。對了,你要的本本我都幫你買了喔。」她從旁邊接過紙袋,棕色的紙袋上是叼著花朵的白髮少女,旁邊寫有white parabellum的字樣,毫無疑問就是白髮教副教主凪白みと的作品。隨著教主三嶋くろね與副教主凪白みと人氣水漲船高,更多繪師也投入了量產白髮少女的行列。在新晉白髮教徒之中偏向成熟風格的ふーろ應該會成為明日之星吧。




我打開紙袋翻出屬於她的本子:「嗯……[音遊機台現況2019 ver.]。那旁邊的[DDR 上級向段位全攻略]有看到嗎?我看你也卡在十段好一段時間了。」


琪魯諾數學教室⑨週年版之基數(cardinal)……那一檔的新刊似乎是low-dimensional topology評論呢,跟你的興趣很像啊。」「……!」















Thursday, 23 January 2020

拉麵食記2020:拉博、燈花、Due Italian



這次我挑空去了一遍橫濱的拉麵博物館。七家拉麵都相當吸引,但我的胃容量只夠我吃其中三家。其中的沖繩麵比較令人失望,但德國和加拿大拉麵都做得不錯,我對這兩家拉麵的感想會在下面詳述。此外我也試了燈花和老面孔Due Italian,每一家都是值得一試再試的拉麵。希望各位看過以後有空也能試一下 :)





Ryu's noodle bar

從無垢拉麵走出來,旁邊的Ryu's noodle bar裡面只坐了一個橫濱風小混混(?)(看DRB太多了),外面也沒有人在排隊。不過既然是雞白就值得我們進去試一下。

我點了西京風味噌雞白迷你拉麵……結果遞上來的根本是full size拉麵,只能說真不愧是加拿大。以小火熬出的雞白非常柔和,味噌則以甜味噌、白味噌為主,與一般的咸味噌拉麵不同以外亦與雞白非常合襯。整碗拉麵的配料是為了讓食客最大程度感受到湯底的甜味:薄切豬肉均勻地分散在湯底裡,雪耳則吸滿了味噌湯底的甜味。拉麵上撒了幾粒乾辣椒,雖然沒有為湯汁帶來甚麼辣感,但直接吃乾辣椒放進口中也是夠嗆--乾辣椒帶來辣感的同時也將口中的甜膩感橫掃一空,讓人有要再來一碗的感覺。




不知為何我總有一種香港有燈花分店的感覺,不過反正都到日本了那試一下也無妨。心裡假設了燈花是高檔拉麵,實際發現它在food court裡面時難免有種無謂的失望。當然食物好不好吃才是重點,金子半之助不也開了在燈花的旁邊嗎?高檔餐廳開在food court反而更好:附近選擇夠多的話大家反而不一定集中排同一家,這樣我們才有機會嚐到這些「高檔拉麵」。



Due Italian



這個假期我一共去了兩次Due Italian。

第一次為了趕上last order我胡亂點了限定的香菜拉麵(?),對於日本人來說略為新奇,不過對東南亞人來說就比較常見。這香菜拉麵其實就是酸辣湯底配上大量香菜、菠菜和炸蒜的台(?)風拉麵。肥叉燒當然是這種重口味拉麵的絕佳配搭,酸和辣的平衡讓人忍不住一口接一口地直接整碗清掉。我覺得這種酸辣湯底是做得挺成功的,就是不清楚日本人能否接受。



第二次帶朋友去,我選的是正月限定肥肝味噌拉麵。價錢讓人嚇一跳,不過既然是Due Italian那試一下也無妨。