I am new to Unity and not game developer at all, so sorry if this question might be stupid. I have an animation in my project. Is there some points where Unity calculates/recalculates the next position of animated character? Is there some function like for example “OnAnimationSample()”? I want to make calculations between theese points. I didn’t found anything in the documentation and hope that someone more experienced than me know some way to tackle, although the task is quite peculiar

# Tag: calculations

## calculations – What is the relationship between size of object with distance?

Inversely linear is a good approximation.

Imagine a 1,7m tall girl at 1 m distance *b*. Her head is at point **B**.

How does the size/length of an object vary with distance?

Let the girl walk away from you. Her size **a** stays the same. She appears smaller, because she is appearing under a smaller angle. Her angular size changes. Try to imagine it with the picture attached.

Using **arctangent to calculate** her angular size is the correct way. For small angles you can simplify:

Angular size is

inversely proportionalto its object distance, without using optical devices.

An object on full-field with focal length of 12 mm would be measured incorrectly. An **error 2-5%** in length measurement may be made. For fish-eye lenses this may be even worse. Hands-on rule: Use the inverse relationship if angular size is smaller than 10°.

## mathematics – Need Help Figuring Out Damage Calculations for Diablo RPG Clone

I’m building a Diablo clone using Unreal Engine 4 and have been having trouble wrapping my head around how the combat calculations should work. I copied a lot of the core stats from the original diablo game as a starting point.

Visited Websites:

How to develop RPG Damage Formulas?

https://diablo.fandom.com/wiki/Damage

http://diablo3blog.blogspot.com/p/diablo-3-damage-explanation-and-guides.html

So for the data model, I’m storing the character stats in a struct called PlayerStatsStruct.h. I also set some limits for how high the stats could go.

PlayerStatsStruct.h:

```
USTRUCT()
struct FPlayerStatsStruct {
GENERATED_USTRUCT_BODY()
FPlayerStatsStruct();
UPROPERTY(EditAnywhere)
FString Name;
UPROPERTY(EditAnywhere)
float TotalExperience;
UPROPERTY(EditAnywhere)
int32 Strength; // MAX OF 99
UPROPERTY(EditAnywhere)
int32 Dexterity; // MAX OF 99
UPROPERTY(EditAnywhere)
int32 Vitality; // MAX OF 99
UPROPERTY(EditAnywhere)
int32 Magic; // MAX OF 99
UPROPERTY(EditAnywhere)
int32 Agility; // MAX OF 99
UPROPERTY(EditAnywhere)
float Health; // MAX OF 1000
UPROPERTY(EditAnywhere)
float Mana; // MAX OF 1000
UPROPERTY(EditAnywhere)
bool Invulnerable;
};
```

Here is the struct I’m using for every monster.

MonsterStatsStruct.h

```
USTRUCT()
struct FMonsterStatsStruct {
GENERATED_USTRUCT_BODY()
FMonsterStatsStruct();
UPROPERTY(EditAnywhere)
FString Name;
UPROPERTY(EditAnywhere)
int32 Level;
UPROPERTY(EditAnywhere)
float Health; // MAX OF 1000
UPROPERTY(EditAnywhere)
float Defense;
UPROPERTY(EditAnywhere)
float AttackSpeed;
UPROPERTY(EditAnywhere)
float AttackDamageMin;
UPROPERTY(EditAnywhere)
float AttackDamageMax;
UPROPERTY(EditAnywhere)
float MovementSpeeed;
};
```

I made these formulas for determining the current Max Mana and Max Health like so:

MaxHealth = 218.f * FMath::Loge(Stats->Vitality) // MAX OF 1000 when Vitality is 99

MaxMana = 218.f * FMath::Loge(Stats->Magic) // MAX OF 1000 when Magic is 99

The main things that I’m stuck on are:

- How do I determine the net damage inflicted on an enemy given both the Player Stats and the Enemy stats?
- What exactly does defense do in combat?
- How is dexterity related to defense?

I think at large the concept is this right?:

TotalDamageToEnemy = PlayerAttack – Enemy Defense

The problem is that the concept of defense is really abstract to me right now.

Thanks for your help.

## Vertex tax calculations

I need to understand how magento handles vertex tax calculations.

I want to know how does magento send request to vertex and what are the parameters needed.

## list manipulation – Why does MatrixForm affect calculations?

David’s answer is correct and the one you need to solve your specific problem. I thought nonetheless that it is worth providing some additional information that might help explain how to diagnose similar issues.

Matrix/tensor operations like `Dot`

and `Inverse`

are designed to work with *lists*, that is, expressions with a `Head`

of `List`

. It also works with `SparseArray`

objects. From the documentation:

When its arguments are not lists or sparse arrays,

`Dot`

remains unevaluated.

You can check whether your expressions have compatible `Head`

s using `FullForm`

. It is common for people to use postfix (`//`

) notation to check this. As you can see, in your version of the code, `a`

has head `List`

while `b`

has head `MatrixForm`

. So they can’t combine.

```
a//FullForm
```

`List(List(1,0,1,0),List(2,1,1,1),List(1,2,1,0),List(0,1,1,1))`

```
b//FullForm
```

`MatrixForm(List(List(0),List(0),List(0),List(1)))`

If you discover you have erroneously created a matrix wrapped in `MatrixForm`

, you can change it back to a list using `First`

.

```
FullForm(First(b))
```

`List(List(0),List(0),List(0),List(1))`

As an aside, I don’t see any point assigning the variable `inv`

to represent the `Inverse`

of `a`

. Unless your real problem uses $a’$ more than once (especially if it is expensive to calculate), you can just as easily do:

`Inverse(a).(First@b)`

Note that I have mixed using of `@`

and `()`

style notation for pedagogical reasons.

## calculations – How to calculate the precision/resolution of a camera

I know there are other questions about this but I couldn’t find the answer I was looking for…

I am developing a control system using a camera and I need to know theoretically the precision/resolution (I am not sure what term to use for this particular case) I can get with this camera. So I need to **calculate the precision of what my camera can see with a given distance**.

Despite searches I really can’t find a formula to know how precise I would be with my camera. Can anyone help on that? Thank you in advance.

```
Data:
- Sensor Size : 3.7 mm x 2.8 mm
- Resolution (HxV) : 659 px x 494 px
- Pixel Size (H x V) : 5.6 µm x 5.6 µm
- Focal length : 16.0 mm
- Distance from the measured surface : 90 mm to 110 mm
```

**EDIT:** I am trying to *measure variability on a surface* with a contrast analysis after a machining. So I need to know how much/small I can measure with the camera in order to know the precision of my system.

## yield – Record probability calculations for censored data in R

I am calculating the probability of data recording that some censored observations have. For uncensored "a" groups, probability calculates P (Y = y). For censored "b" groups, calculate that Y is *at least* size Y, P (Y≥y). So the probability is L = mult (P (Y = y) P (Y≥y)).

The following code is my actual working code in use which calculates this registration probability based on the censorship status. However, when it is in place with various other functions, it is extremely slow since you have to iterate through each row in the dataset (datasets are generally several thousand rows long, and maximization runs through several thousand iterations of R and k values).

I hope someone knows an alternative way of approaching this that increases performance. I am not (obviously) an expert encoder.

```
new_likelihood <- function(Y,R,k) {
p_function <- function(y,n){ #Create a dummy function to use in for loop
exp(log(n)-log(y)+lgamma(k*y+y-n)-(lgamma(k*y)+lgamma(y-n+1))+(y-n)*log(R/k)-(k*y+y-n)*log(1+R/k))
}
liks_a <- numeric(nrow(Y)) # initialize vector of logliks for `a` clusters
liks_b <- numeric(nrow(Y)) # initialize vector of logliks for `b` clusters
#Loop through each row of the data
for(i in 1:nrow(Y)){
y <- Y(i,1)
n <- Y(i,2)
c <- Y(i,3)
if (c==0){ #For uncensored, apply regular PDF
liks_a(i) <- log(p_function(y,n))
} #outputs a value of 0 in liks_a(i) if c=1, so doesnt affect sum(log(liks))
if(c==1){ #for censored, sum to do 1-(sum(Y-1))
liks_b(i) <- log(1-sum(p_function(1:(y-1),n)))
} #outputs a value of 0 if in liks_b(i) if c=0, so doesnt affect sum(log(liks))
}
sumliks <- sum(liks_a,liks_b)
return(sumliks)
}
# Example data
Y_censor0 <- cbind(c(3,2,2,10,1,1),c(1,1,1,1,1,1),c(0,0,0,0,0,0)) # 3-column data w/ no one censored
Y_censor1 <- cbind(c(3,2,2,10,1,1),c(1,1,1,1,1,1),c(0,0,1,1,0,0)) # 3-column data with some censored
# Test
new_likelihood(Y_censor0,0.9,0.25)
new_likelihood(Y_censor1,0.9,0.25)
```
```

## java: background calculations cannot be run correctly with Services / AsyncTask

This is a developing application code. The theme is that the user selects a maximum of 50 images and then displays them in different designs. These designs can be, that a design consists of 6 images … second 5 … so in 50 images they will be shown in different designs. The problem is, when the service ever runs. Sometimes it runs smoothly and returns design information. Sometimes the system simply suspends the execution of the running service and no results are returned. I used Intent Service to process information in the worker thread, but still sometimes the information is processed, sometimes the system just skips processing the service in progress.

MainActivity.java

```
onActivityResult()
{
//...
//..
//..
//..
//..
//MasterImageList is basically the retrieved images with their local path as string
val myService = Intent(this,LayoutsProcessing::class.java)
myService.putExtra("masterImageList",masterImageList)
startService(myService)
}
override fun onResume() {
super.onResume()
Log.d("MyTag","On Resume")
LocalBroadcastManager.getInstance(applicationContext).registerReceiver(mReceiver,
IntentFilter(LAYOUTS_PROCESSING_RESULT)
)
}
override fun onPause() {
super.onPause()
Log.d("MyTag","On Pause")
LocalBroadcastManager.getInstance(applicationContext).unregisterReceiver(mReceiver)
}
```

```
```//Receiver

private var mReceiver = object : BroadcastReceiver() {
override fun onReceive(contxt: Context?, intent: Intent?) {
if(intent!=null) {
if(intent.hasExtra("map")){
val result:HashMap> =
intent.getSerializableExtra("map") as HashMap>;
val multiCollageIntent = Intent(applicationContext, DisplayAlbumCollage::class.java)
multiCollageIntent.putExtra("map", result)
val myService = Intent(applicationContext,LayoutsProcessing::class.java)
multiCollageIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
stopService(myService)
startActivity(multiCollageIntent)
finish()
}
else{
Toast.makeText(applicationContext,"I am g=hit",Toast.LENGTH_SHORT).show()
}
}
}
}

LayoutsProcessing.java

public class LayoutsProcessing extends IntentService {
private static final String TAG = "MyTag";
public static final String LAYOUTS_PROCESSING_RESULT = "LayoutsProcessingResult";
private String() masterImageList;
int totalImageSize;
HashMap> result = new HashMap();
public LayoutsProcessing() {
super("LayoutsProcessing");
setIntentRedelivery(true);
}
@Override
public void onCreate() {
Log.d(TAG, "onCreate: ");
super.onCreate();
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
if(intent!=null) {
masterImageList = intent.getStringArrayExtra("masterImageList");
totalImageSize = masterImageList.length;
}
}
private void sendResultToUI(HashMap> result) {
Intent intent = new Intent(LAYOUTS_PROCESSING_RESULT);
intent.putExtra("map",result);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy: ");
super.onDestroy();
}
private HashMap> makeCollageMapForViewPager(ArrayList pageNumberSize) {
HashMap> collageMap = new HashMap>();
int startIndex = 0;
int i = 0;
try {
for(Integer pageSize: pageNumberSize ) {
int getTotalCollageImages = pageSize;
int end = startIndex + getTotalCollageImages;
int arraySize = end - startIndex;
ArrayList images = new ArrayList(arraySize);
for (int k=startIndex; k> generateRandomLayouts(int totalImageListSize)
{
ArrayList pageNumberSize = new ArrayList();
int remainingImagesSize= totalImageListSize;
int randomNumber;
Random r = new Random();
randomNumber = r.nextInt(7 - 2) + 2;
int totalNumberOfPages = 0;
while (remainingImagesSize != 0) {
if (randomNumber > remainingImagesSize) {
randomNumber = r.nextInt(7 - 2) + 2;
} else {
remainingImagesSize -= randomNumber;
Log.d("MyTag Page Number", String.valueOf(totalNumberOfPages));
pageNumberSize.add(randomNumber);
totalNumberOfPages++;
randomNumber = r.nextInt(7 - 2) + 2;
}
}
return makeCollageMapForViewPager(pageNumberSize);
}
}

```
```

```
```

```
```
## layout: positioning of div elements without server calculations

I have created a site that has a dynamically created menu, which pulls tabs, according to some fixes in the backend. Selecting a tab retrieves the entire page, with different CSS classes applied, depending on the tab selected.

Basically i'm using `style="position: absolute; left: xxxxpx"`

where he `xxxx`

it is concatenated in the backend.

I want to change the site so that the graphical user interface is more independent of the backend.

I'm not sure how to go about changing this so all design calculations are done using CSS. I was thinking of doing it with css variables and keeping the same essential code, but I am not sure how to determine which node and therefore how far should be offset.

## First tab selected

## 3rd tab selected

## CSS

```
.tab-admin{
background-color: var(--admin-tab-bg);
}
.tab-design{
background-color: var(--design-tab-bg);
}
.tab-project{
background-color: var(--project-tab-bg);
}
.topTabSelected {
position: absolute;
top: 31px;
z-index: 8;
color: white;
font-weight: bold;
border-left: 1px solid black;
border-top: 1px solid black;
border-right: 1px solid black;
border-bottom: transparent;
padding: 3px;
border-radius: 5px 5px 0 0;
width: 120px;
height: 17px;
text-align: center;
}
.topTab {
position: absolute;
top: 31px;
z-index: 2;
color: white;
font-weight: bold;
border-left: 1px solid black;
border-top: 1px solid black;
border-right: 1px solid black;
padding: 3px;
border-radius: 5px 5px 0 0;
width: 120px;
text-align: center;
}
.topTab a {
text-decoration: none;
color: white;
}
.topTab a:hover {
text-decoration: underline;
color: white;
}
```

## Backend code to calculate positions:

```
$tabwidth = 132;
$widthmodifier = 200;
for ($mainpageCounter = 1; $mainpageCounter <= count($mainpage); $mainpageCounter++) {
$topTabDivStart = "n";
$topTabDivEnd = "n";
if ($p == $mainpageCounter) {
echo $topTabDivStart . $mainpage($mainpageCounter)("title") . $topTabDivEnd;
} else {
echo $topTabDivStart . "" . $mainpage($mainpageCounter)("title") . " $topTabDivEnd";
}
$widthmodifier += $tabwidth;
}
```

## functions: how does following two (same) calculations give two different results?

I have the following two pieces of code that give me two different results,

```
N((-Kp tp + Lc - tp Lc)/(Kp tp)) /. {Lc -> 6, tc -> 0.8, tp -> 0.2, Kp -> 1/3}
```

Which gives the answer as 23 (The correct answer).

```
(-Kp tp + Lc - tp Lc)/( Kp tp) /. {Lc -> 6, tc -> 0.8, tp -> 0.2, Kp -> 1/3}
```

Which gives the answer as 3 (which is obviously wrong).

Could someone explain how / why this happens and how to avoid this (possible) error?

Below is the image of the calculation on my machine:

```
```