Objective C - SKEmitterNode position range - position

Question is how to define a non-rectangular shape for emitter node position range?
By position range I mean this:
emitter.particlePositionRange = CGVectorMake(50,75);
Is there some workaround to make this area triangular instead of rectangular?

Related

How can I calculate the area of a slice of a superellipse?

Say I have a superellipse with a given width, height and eccentricity (n). I want to create x horizontal slices of equal height. How can I calculate the area of each slice?
I don't even need exact values for the specific project I'm working on, only close approximations.
You can make integral for area of superellipse slice like this (4) and integrate it numerically in needed range instead of 0..a
I think that for approximation simple method of midpoint rectangles is enough:
for slice interval y0..y1 choose number of sub intervals n, step h = (y1-y0)/n and calculate function value (y instead of x) in points y0 + h/2 + h*i, i = 0..n-1, then sum these values and multiply sum by y1-y0.

detect if excel bubble chart bubbles overlap or determine exact bubble size

I'm trying to make some infographics based on a worldmap and bubbles, kind of like this:
Each bubble represent a country, and the size of the bubble the volume of coffee production (in this example). The exact position of the country does not really matter, as long as it's in the right regional group, but I can't let the bubbles overlap.
So I'm trying do write a macro that will adjust the X and Y coordinates of each data point, so that they don't overlap.
But for that I need to detect if bubbles overlap. What I'm thinking is simply to check the distances between the bubble centers with Xs and Ys, and compare with the bubble radius.
Hence my question: how can I determine the actual size of the bubbles? (not with the scale, but the actual size of the bubble, given the scale). I noticed they adjust based on the biggest one, which seems to be a fixed proportion of the smallest dimension of the plot area. So far it seems to be R=~ 1.29 x smallest plot area dimension, but is it always the case?
Also, if I need to change the scale, how exactly does it change the bubble size? (a scale of 200 does not seem to correspond to a sqrt(2) bigger radius)
Thanks a lot in advance!
Luc
Sub y()
Dim c As Chart
Dim s As Series
Dim p As Point
Set c = ActiveSheet.ChartObjects(1).Chart
Set s = c.SeriesCollection(1)
Set p = s.Points(1)
Debug.Print p.Left, p.Top, p.Width, p.Height ' Will be the same height & width as circle.
End Sub

How to iteratively apply a function to groups of data in Excel

So I'm quite new to using excel and it's possible I missed over a question like this that was already answered, but what I am trying to do is measure the distances between groups of points in a large excel sheet.
I've tried the standard way of writing a function and dragging it down but the way the function changes when I move it down is not what I need and I can't seem to figure how how I might fix this so I think a macro might be the solution.
The data is groups of 8 measurements with every group having one Blue, Red, Yellow, Csome, Overlap, Green, Cyan, and Full object. The XYZ coordinate of each object is listed in the first three columns and using a simple distance formula I am trying to measure the distance between each object and all the other objects in it's same group. Eg. Blue to Red, Yellow, Csome... etc. Then again for Blue2 to Red2, Yellow2, Csome2... and Blue3 to Red3, Yellow3, Csome3... and so fourth.
However, when I put the following formula in where my desired output should be and try to drag it down, obviously I run into some problems. For the first Blue against it's whole group, I begin with =SQRT((A$2-A2)^2+(B$2-B2)^2+(B$2-B2)^2) and drag it down so it cycles through row 2 versus rows 3,4,5,6,7,8,and 9. The issue arises when I get to row 10 which contains Blue2. This should not be compared with Blue1 but rather begins a new group. How then can I get the cycle to restart at row 10 so that the new group beginning with Blue 2 is compared within that group, eg the XYZ in row 10 to XYZ in 11, 12, 13...
:
Position X Position Y Position Z Unit Category Collection Surpass Object
16.38 41.20 4436.18 um Surface Position Blue Selection
17.35 40.83 4436.17 um Surface Position Red Selection
15.93 40.62 4435.93 um Surface Position Yellow Selection
16.22 40.80 4436.03 um Surface Position Csome1
17.97 42.23 4435.46 um Surface Position Overlap
15.37 40.87 4436.03 um Surface Position Green Selection
15.44 40.04 4436.39 um Surface Position Cyan Selection
17.97 42.23 4435.46 um Surface Position Full 1
15.57 36.20 4435.75 um Surface Position Blue Selection 2
12.83 35.19 4435.33 um Surface Position Red Selection 2
15.76 37.25 4435.74 um Surface Position Yellow Selection 2
14.94 36.17 4435.65 um Surface Position Csome2
15.99 36.78 4436.34 um Surface Position Overlap 2
14.23 36.26 4435.57 um Surface Position Green Selection 2
13.61 36.96 4436.09 um Surface Position Cyan Selection 2
14.64 36.42 4435.80 um Surface Position Full 2
42.83 36.04 4435.47 um Surface Position Blue Selection 3
42.34 36.56 4435.63 um Surface Position Red Selection 3
42.25 36.87 4435.75 um Surface Position Yellow Selection 3
42.48 36.50 4435.62 um Surface Position Csome3
41.77 36.02 4435.67 um Surface Position Overlap 3
42.64 36.89 4435.73 um Surface Position Green 3
42.05 36.90 4436.21 um Surface Position Cyan Selection 3
42.34 36.53 4435.71 um Surface Position Full 3
33.75 33.13 4436.32 um Surface Position Blue Selection 4
34.99 33.12 4436.38 um Surface Position Red Selection 4
35.40 31.97 4436.38 um Surface Position Yellow Selection 4
34.75 32.58 4436.36 um Surface Position Csome4
39.03 35.24 4436.04 um Surface Position Overlap Selection 4
35.49 32.19 4436.49 um Surface Position Green Selection 4
36.14 32.35 4436.42 um Surface Position Cyan Selection 4
36.16 33.20 4436.30 um Surface Position Full 4
Applying some VBA to loop through the matches to Full with a wildcard and reset the formula's starting row for each iteration should be the best way to go with this.
Sub Group_Formula()
Dim frmla As String, rw As Long, rws As Long, n As Long, cnt As Long
frmla = "=SQRT((A$×-A×)^2+(B$×-B×)^2+(B$×-B×)^2)"
With ActiveSheet '<-set to worksheet name properly!
For cnt = 1 To Application.CountIf(.Columns("G"), "Full*")
rw = Application.Max(2, rw)
rws = Application.Match("Full*", .Cells(rw, "G").Resize(Rows.Count - rw, 1), 0)
.Cells(rw, "H").Resize(rws, 1).Formula = Replace(frmla, Chr(215), rw)
rw = rw + rws
Next cnt
End With
End Sub
The results should resemble the following.
    
You need to handle the A$2, B$2 references with a function that will calculate the row. You can use reference functions like INDEX, INDIRECTor OFFSET to accomplish what you need. The last two are volatile, so keep in mind they recalculate every time a value changes in your sheet. INDEX is more efficient.
It isn't clear if your data includes the group number because the numbers at the end of the row are inconsistent. If they are consistent in your data you can use them. Supposing the group number is in column I, This INDEX formula will return the correct A$2 reference:
INDEX($A$2:$A$33,1+((I2-1)*8))
Or with the OFFSET function:
OFFSET($A$2,(I2-1)*8,0)
Otherwise, (without using the group number) you can use the ROWS function to produce a similar result:
INDEX($A$2:$A$33,1+QUOTIENT(ROWS(A$2:A2)-1,8)*8)
The 8 in all the formulas represent the number of items in a group.
And the full formula would be:
=SQRT((INDEX($A$2:$A$33,1+QUOTIENT(ROWS(A$2:A2)-1,8)*8)-A2)^2+(INDEX($B$2:$B$33,1+QUOTIENT(ROWS(B$2:B2)-1,8)*8)-B2)^2+(INDEX($C$2:$C$33,1+QUOTIENT(ROWS(C$2:C2)-1,8)*8)-C2)^2)
Well as a new excel user you've jumped straight into the wonderful and perplexing world of array formula's.
First you need to prep your data a bit. All those 1s, 2s, 3s and 4s need to be in a column of their own, all those in group 1 need a number, and everything needs to be named consistently ('Green' vs 'Green Selection'). We could make the formula even more complex to account for these idiosyncracies in your data, but cleaning it will make understanding it and the formulas easier.
Now we put the "Surpass Object" we want to calculate the distance from in Cell I1 (in this case 'Blue Selection') and the following formula into cell I2 being sure to hold ctrl+shift+enter when we enter it.
=SQRT((INDEX($A$2:$A$33,MATCH(1,($G$2:$G$33=I$1)*($H$2:$H$33=$H2),0))-$A2)^2+(INDEX($B$2:$B$33,MATCH(1,($G$2:$G$33=I$1)*($H$2:$H$33=$H2),0))-$B2)^2)
This will get us the distance between the x and y co-ordinates for each. You'll need to adjust the formula to add the z-coordinate to the calculation if you need it.
So what is the fancy index-match formula doing? In the first instance it grabs the cell in column a, that matches both the 'Surpass Object' in the column header (cell J$1) and the group of the current row (cell $H2)
Now you can just fill in the remaining headers and fill the formula right and down to get your matrices of differences

Position a shape in Excel based on its center point

Is it possible to position a shape by its center point?
I'm trying to overlay shapes onto a picture of a map in Excel and adjust the size of the shapes based on the value in a cell.
I have the sizing portion figured out, but every time my shapes size increases it slowly starts to move to the right and bottom due to the positioning of its left and top. I would like it if the positioning of my circles would not moved once the data gets refreshed. I only want the size of the shape to be altered.
Any thoughts?
If you know the X/Y (really Left/Top, since {0,0} is upper left) where you want to put it, it is as simple as subtracting off half the size of the shape to get the center to be there.
Here is some simple code which puts the center of a circle at the corner of cell E8. I assume you have some way of selecting the shape based on your question.
Sub PositionByCenter()
Dim dbl_x As Double
Dim dbl_y As Double
'select a cell just to put it somewhere
dbl_x = Range("E8").Left
dbl_y = Range("E8").Top
'grab a reference to a shape
Dim shp As Shape
Set shp = Selection.ShapeRange.Item(1)
'position by the center
shp.Top = dbl_y - shp.Height / 2
shp.Left = dbl_x - shp.Width / 2
End Sub
Here is what you get after running that with a circle selected.

Shape adjustment in excel 2010

I insert a shape of type rounded rectangular callout at run time and initially its pointer's direction is downward.If i check its value using
shp.Adjustments.Item(1)
code then it shows its value -0.20833
I want to change its direction to upward.I recorded a macro to adjust that and got this code
Selection.ShapeRange.Adjustments.Item(1) = -0.20223
But still its direction is downward.
Please help to set its direction to upward.
I would suggest just rotating the shape 180 degrees on the y axis. This rotates the shape, but as you note it also rotates the text which may not be desirable.
shp.ShapeRange.ThreeD.RotationY = -180
If you simply want to adjust the pointer from the callout, this is Item(2). When I create a shape, it has a value like:
shp.Adjustments.Item(2) = 0.625
To reverse its location, so that it is on the top of the rectangle, change it to:
shp.Adjustments.Item(2) = -0.625

Resources