How to implement bounce off collision between two nodes in ARKIT-Scenekit of iOS 11? - scenekit

I am trying to implement collision bounce off between two nodes. From what i learnt, collision property will be set by default and if there is any contact between two nodes, it will bounce back. I have multiple virtual 3D objects that i add into scene. There is a provision for user to move the object anywhere. For example, let us say i have two objects table and chair, if i move chair towards the table, the chair overlaps with the table. But what i need is chair should bounce back since we already have table in that position.
I have multiple objects placed liked this. And user can move any object anywhere. But no two objects should overlap with each other.
I tried setting contactbitmask and collisionbitmask but no luck(I have 6 scenefiles and i have given values from 1, 2, 4, 8, 16, 32 as category masks and 62, 61, 59, 55, 47, 31 as collision and contact masks respectively for nodes of each scenefile).
I even tried using contactTestBetween but no idea what it returns and how to find out if there is contact between two bodies using this method. I understand it returns point of contact, impulse, penetration distance etc. but with these how to find out if there is contact between 2 nodes?

Related

Actionscript 3, parsing giant tables of external data into usable arrays

I have a basic understanding of AS2 and AS3. I previously tried creating giant arrays in my file so that I could compare arrays against each other, but it would be far better to have the data tables as external files since there is so much of it. If I want to scale up my analysis, there are millions of entries in total. Ideally I can click a button and then it only loads in the part that is needed. All data is meant to be static in their files. If the data needs modifying, I'll do it manually in the text files.
The way I set up tables are vertical. EX:
Year 1:
Name: Person 1, Person 2, Person 3, Person 4
Q1: 25, 22, 21, 14
Q2: 14, 25, 19, 33
Etc.
Year 2:
Name: Person 1, Person 2, person 3, Person 4
Q1: 21, 15, 11, 6
Q2: 8, 35, 22, 9
Etc.
I have found multiple suggestions on here for parsing txt files, but I remain unclear on how to pull in a table like this and turn it into an array. In this case, Name array would be [Q1, Q2,...]. Person 1 would be [25, 14,...] Since the array is nested, it would only contain data from Year 1. If I can get the basics of this working, the rest is just converting all my tables to txt files and just grinding through.
A bit more background: I'm using Flash to help visualize data since I can draw and do color changes easily in it. There are probably better software out there. I think I'm going the right direction, but if I'm making big mistakes in my assumptions, please correct me. There's other suggestions on here for other formats and methods, in theory the data could be put directly into another flash file as an array and included when needed, that might also work. Once again, I have a smaller scale of this working with the arrays just straight in Flash, it's just going to eventually die if I try and scale up. Thanks for your time.

Stata / Loops to delete every 9th-15th observation out of 15,000 observations

I am trying to create a loop that deletes every 9th-15th observations out of dataset containing around 15,000 observations. What would be the syntax?
In general you should not loop over observations as there is almost definitely a more efficient and elegant solution, as Nick noted above with the drop if missing(turnout) solution. However, I gather you are a new Stata user so I will run through a hypothetical. Suppose that you in fact did want to drop observations within a certain range rather than based on a secondary variable like turnout. The general strategy could be as follows:
Group observations in groups of 15 (which I think you have here with the id column). In the solution below I will assume you do not have this column.
Within each group, drop the observations in the 9th-15th places.
// Group observations
gen group = ceil(_n/15)
// Within each group, drop in the 9-15 locations
by group: drop if inrange(_n,9,15)
drop if mod(_n, 9) == 0
will drop observations 9, 18, 27, and so forth. The same principle applies to any other positive integer.

Can a cache be used for an alpha-beta search algorithm?

I'm working on a minimax tic-tac-toe algorithm. I got it working fine, caching each state in the tree.
Then I implemented alpha-beta pruning, which seemed to affect the game. I think the problem is that nodes cannot be "trusted" if any of their descendants (children, grandchildren, etc.) were pruned. Is this true?
For now, I'm only caching states if they don't have pruned descendants. This image shows my point (not tic tac toe). The max player is the upwards triangle, which should choose the move on the left. However, if the move on the right is cached during alpha-beta pruning, the red triangle will have a false value of 4, so the move on the right would be wrongly chosen.
If by a "cache" you mean a transposition table, then you can't always trust the value in the transposition table. That is, when you store a value in a transposition table, you need to also store the alpha and beta values (perhaps the depth as well) used for the search below that state. If the alpha and beta values are not the same*, then you can't use the value from the transposition table.
*In practice they don't have to be identical, the table just needs to have values that include a superset of the values used at the current node you want to replace with the cached values.
Edit: Additional info for those dealing with this in larger games. When you search at a node you have a lower bound (alpha) and upper bound (beta) on the final value. If the returned value is between alpha and beta, then you know it is the true value of the state. If it is equal to alpha or beta, then you know it is only a bound on the final value. But, you can still use this information to help the search.
In particular, suppose that you have alpha=10 and beta=20 in the current search and the value in the transposition table is [alpha = 12, beta = 30, value = 12]. Then, when you (re-)search below the branch, you can search with bounds of alpha=10 and beta=12.
This is because you've already proven that the value is <= 12 in the previous search. When you get the final result, you can then update the transposition table entry to reflect the additional information from this search.

Filemaker Database design for Film project

I have been asked to create a database to track the frames in a short industrial video.
I have 10,000 frames which are each referenced in a container field in Table "Thumbnails" with an associated frame number (a positive 6-digit integer).
I have another Table, "Shots" which contains: Shots (text, a shot name), Shot order (a decimal number), Frame IN (an integer number), Frame OUT (another integer), and duration (a calculated value from Frame In to Frame out)...
I want to be able to call up the thumbnails in a container, so that if I call up shot 1001, i can see all the thumbnail frames from table 2, which apply to the shot in question, using the frame numbers in the Thumbnails table, and the Frame IN/OUT/Duration in the "Shots" table records...
Thing is, I have never tried to join table together or pull from 2 tables to get a result. I know this is a big question, but I was hoping someone might be able to point me in a direction to start, using Filemaker Pro 11.
Currently, the frame numbers get imported with the frame file, which is defined by the image filename. So I have to use those numbers when looking for frames in the "Thumbnail" table.
Any thoughts at all would be a huge help to me.
If you define a relationship between the two tables as:
Shots::FrameIn ≤ Thumbnails::FrameNumber
AND
Shots::FrameOut ≥ Thumbnails::FrameNumber
you will be able to view all shot's frames in a portal to Thumbnails, placed on a layout of Shots.

Test if a column is a superset of predefined set of data

I'm trying to compare teams' compositions to known configurations in order to see where I might have a problem :
The trials columns are to be compare against the differents scenarios to see if a column is a superset of a particular scenario (error being default).
Can it be done using index+match/lookup, or do I have to write some VB macro ?
EDIT : I've updated the question with a worksheet with input data.
Worksheet : https://drive.google.com/file/d/0BxwDbXStIEAsUmpONHp1RVRzR2s/edit?usp=sharing
Github Gist : https://gist.github.com/lucasg/11177852 (python script for data gen)
(xlwt module needed to create excel workbooks).
I've simplified the problem using soccer teams : given 7 positions ( 1 goalie, 2 defenders, 2 midfield and 2 forward) and list of presence to certains week-end, I would like to know whether I'm gonna be able to provide a full team or am I to forfeit the match due to lack of key-players.
The positions :
styles = {
"Goalkeeper" : ["Goalkeeper"],
"Defender" : ["Centre back", "Wing"],
"Midfielder" : ["Centre midfield", "Wide"],
"Forward" : ["Centre forward","Winger"]
}
Most football players can play only one position, but some are more versatile and can play any positions in their own field (defense-midfield-attack).
Example of a team (18 pers.):
example_players = {
"Forward": [
[1, "Winger"],
[2, "Winger"],
[3, "Centre forward"],
[4, "Centre forward"]
],
"Defender": [
[5, "Centre back"],
[6, "Centre back", "Wing"],
[7, "Centre back", "Wing"],
[8, "Wing"],
[9, "Centre back"]
],
"Goalkeeper": [
[10, "Goalkeeper"],
[11, "Goalkeeper"]
],
"Midfielder": [
[12, "Centre midfield"],
[13, "Centre midfield"],
[14, "Wide", "Centre midfield"],
[15, "Centre midfield"],
[16, "Centre midfield"],
[17, "Wide", "Centre midfield"],
[18, "Wide", "Centre midfield"]
]
}
To make it more simple, I need at least one person in each zone (goal-def-mid-attack) to be able to play, the most comfortable situation being one person in each of the 7 positions.
ex scenario :
"no_defense_4" : ["Goalkeeper", "Wide", "Winger" ] ,
"no_attack_1" : ["Goalkeeper", "Centre midfield", "Centre back", ] ,
Now, given a list of a hundred weekends, and the list of the presence/abscence of players, I want to know the resulting situation.
I'm looking preferentially for a formula-based solution, since the worksheet will be uploaded and used in google drive
You can represent sets as bit vectors and then use bit operators "equal" or "AND" to test which sets get matched. Using bit vectors as set representation will solve problem of ordering and duplicate values automatically as position of each value in the bit vector is fixed and each bit will be "set" only once, regardless of how many times the value appears in the column that defines the set.
Simple to use bit vector representation in Excel including operators OR, AND, NOT is listed here: http://chandoo.org/wp/2011/07/29/bitwise-operations-in-excel/#comment-207723
For example following function
=POWER(10;0)*MIN(COUNTIF($B$3:$B$12;"T1");1)+POWER(10;1)*MIN(COUNTIF($B$3:$B$12;"T2");1)+POWER(10;2)*MIN(COUNTIF($B$3:$B$12;"S");1)+POWER(10;3)*MIN(COUNTIF($B$3:$B$12;"PL");1)+POWER(10;4)*MIN(COUNTIF($B$3:$B$12;"CC");1)+POWER(10;5)*MIN(COUNTIF($B$3:$B$12;"GC");1)
Converts values in the range $B$3->$B$12 into a bit vector representation having bits 0..5 defined so that the bit is set if the value in any column in the range is equal to:
bit 0 = T1
bit 1 = T2
bit 2 = S
bit 3 = PL
bit 4 = CC
bit 5 = GC
You can add more bits with other values easily by following the same copy/paste pattern.
So to check if certain column matches certain scenario, just compare the bit vectors. Use expression like IF(x=y;"warn2";IF(..)) and substitute bit vector of the column for x and bit vector of the warn2 scenario for y.
If partial matching is needed, you can use the bitwise AND operator as defined in the above article.
This solution as opposed to a VBA-based solution will require some copy/pasting discipline, e.g. when new trial column or new scenario will be added few expressions will have to be copy/pasted and few will have to be updated.
VBA-based solution might solve this maintenance problem automatically for you by using auto-detected CurrentRegions, all necessary logic hidden behind one macro-click.
EDIT: The bit vectors concept applied to the new soccer teams dataset
Worksheet: https://docs.google.com/spreadsheet/ccc?key=0AtZPnBk7a3pvdHcyWDV6ZFFoUTNyWWF0bjl3VFpaRkE&usp=drive_web#gid=0
As it is ambiguous what will be the exact team setup on a given day as one player may be assigned different positions, I have simplified the problem in such a way that instead of "present" or "absent" I expect the table to contain player's position. It should not be a problem to achieve as if you know what positions the player can play then instead of absent,present you can define the set of valid values to be (empty or anything else),Midfielder,Centre midfield,Wide for players 14,17,18. List of valid available values can be configured for each cell using the "Data validation" rules. The abstract role Midfielder stands for "this player can play a midfielder, exact position is not known yet".
To represent positions I use bit vector calculated with this formula
=POWER(10;6)*MIN(COUNTIF(D2:ZZ2;"Goalkeeper");1)+POWER(10;5)*MIN(COUNTIF(D2:ZZ2;"Centre back");1)+POWER(10;4)*MIN(COUNTIF(D2:ZZ2;"Wing");1)+POWER(10;3)*MIN(COUNTIF(D2:ZZ2;"Centre midfield");1)+POWER(10;2)*MIN(COUNTIF(D2:ZZ2;"Wide");1)+POWER(10;1)*MIN(COUNTIF(D2:ZZ2;"Centre forward");1)+POWER(10;0)*MIN(COUNTIF(D2:ZZ2;"Winger");1)
the formula calculates bit vector from a range D2:ZZ2 in such a way so that each position in the range is counted only once and in final vector each position has a fixed place. It is useful to set number format of the vector to custom numeric format 0000000. For example a row containing Wide,Winger,Goalkeeper in any order with any number of repeats will evaluate to vector 1000101 where the left-most bit 6 stands for Goalkeeper and 2nd from the right goes bit 2 standing for Wide. The most comfortable situation is the one with bit vector evaluating to 1111111. The only purpose of this bit vector is to detect the comfortable situation
For matching scenarios to team setups I use another vector composed of 4 digits with this meaning:
leftmost digit 3 - number of goalies (at most 1 counts)
digit 2 - number of defenders (at most 2 counts)
digit 1 - number of midfielders (at most 2 counts)
rightmost digit 0 - number of forwards (at most 2 counts)
The formula to calculate this vector for range D2:ZZ2 looks like this
=POWER(10;3)*MIN(COUNTIF(D2:ZZ2;"Goalkeeper");1)+POWER(10;2)*MIN(COUNTIF(D2:ZZ2;"Defender")+COUNTIF(D2:ZZ2;"Centre back")+COUNTIF(D2:ZZ2;"Wing");2)+POWER(10;1)*MIN(COUNTIF(D2:ZZ2;"Midfielder")+COUNTIF(D2:ZZ2;"Centre midfield")+COUNTIF(D2:ZZ2;"Wide");2)+POWER(10;0)*MIN(COUNTIF(D2:ZZ2;"Forward")+COUNTIF(D2:ZZ2;"Centre forward")+COUNTIF(D2:ZZ2;"Winger");2)
It is useful to set number format of the vector to custom numeric format 0000. This same formula can calculate the 4-digit vector for team setup and for scenario.
Besides position names it can count also abstract position names like Defender.
For example in a row containing Centre back,Centre back,Goalkeeper,Goalkeeper,Goalkeeper,Defender,Defender,Midfielder,Midfielder,Winger the vector looks like 1221.
There are (1+1)*(2+1)*(2+1)*(2+1) = 54 different possible scenarios. I assume each of them is listed in the constraints sheet. You should be able to generate them all in python quite easily.
There are 2 sheets constraints with scenarios and events with days and team setups. The lookup formula that takes the vector calculated for a team setup in row #2 and searches the constraints sheet for a row with exactly the same vector and returns the value from the value column looks like this
=IFERROR(VLOOKUP($A2;constraints!$A:$B;2;FALSE);"?")
$A2 - contains the 4-digit vector formula for the team setup
constraints!$A - column in the sheet with scenarios containing the 4-digit vector formula for the scenario
constraints!$B - column in the sheet with scenarios containing the scenario name - the thing you are looking for
2 - index of column constraints!$B
FALSE - means the lookup column does not have to be sorted
? - fallback value if no matching scenario was found (should not occur)
The Google docs link above contains the formulas, example 3 days and example 11 scenarios.
If there's something unclear let me know and I'll improve the answer as the Google docs link will vanish some day

Resources