  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Use attractor point with a vector to change size of small cubes  » development » Use attractor point with a vector to change size of small cubes

By : HiF
Date : November 21 2020, 11:01 PM
it should still fix some issue Ok somehow I managed to answer my own question with this schema of pluggin code : ## Break down cubes into 8 smaller cubes recursively (when the cubes are defined by a mid point and size)

By : Lars Werner
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm still not quite sure if this is what you want, but here is how I woud do it:
First, I would create a class representing points in 3D space:
code :
``````class Point3D:
"""Representation of a point in 3D space."""
def __init__(self, x, y, z):
self.x = x
self.y = y
self.z = z

>>> Point3D(1, 2, 3) + Point3D(100, 200, 300)
Point3D(101, 202, 303)
"""
x = self.x + other.x
y = self.y + other.y
z = self.z + other.z
return Point3D(x, y, z)

def __mul__(self, a):
"""Multiply a point with a number.

>>> Point3D(1, 2, 3) * 2
Point3D(2, 4, 6)
"""
x = self.x * a
y = self.y * a
z = self.z * a
return Point3D(x, y, z)

def __rmul__(self, a):
"""Multiply a number with a point.

>>> 2 * Point3D(1, 2, 3)
Point3D(2, 4, 6)
"""
return self.__mul__(a)

def __repr__(self):
return 'Point3D({p.x}, {p.y}, {p.z})'.format(p=self)
``````
``````from __future__ import division
from itertools import product

class Cube:
"""Representation of a cube."""

# directions to all eight corners of a cube
DIR = [Point3D(*s) for s in product([-1, +1], repeat=3)]

def __init__(self, center, size, depth=0):
if not isinstance(center, Point3D):
center = Point3D(*center)
self.center = center
self.size = size
self.depth = depth

def __repr__(self):
return 'Cube(center={c.center}, size={c.size}, depth={c.depth})'.format(c=self)

def _divide(self):
"""Divide into eight cubes of half the size and one level deeper."""
c = self.center
a = self.size/2
d = self.depth - 1
return [Cube(c + a/2*e, a, d) for e in Cube.DIR]

def divide(self, target_depth=0):
"""Recursively divide down to the given depth and return a list of
all 8^d cubes, where d is the difference between the depth of the
cube and the target depth, or 0 if the depth of the cube is already
equal to or less than the target depth.

>>> c = Cube(center=(0, 0, 0), size=2, depth=1)
>>> len(c.divide(0))
8
>>> len(c.divide(-1))
64
>>> c.divide(5) is c
True
>>> c.divide(-1).size
0.5
"""
if self.depth <= target_depth:
return [self]
smaller_cubes = self._divide()
return [c for s in smaller_cubes for c in s.divide(target_depth)]
``````
``````# minDepthLevel = 0
# grid = {}
# grid[(1.5,0,0)] = [1,2]
# not sure what this ^ 1 means

cube = Cube((1.5, 0, 0), 4, 2)
grid = {c.center: [1, c.depth] for c in cube.divide(0)}
`````` ## sizeWithAttributes gives the wrong height with NSFont on a mac when the point size is very small

By : Vasily Kalachev
Date : March 29 2020, 07:55 AM
it should still fix some issue I am working on a mac app that lets the user zoom pretty far in on the content. I need to measure the size of text that I render. When I scale the font for the zoom the point size of the font is very small (i.e. 0.001). When I use [NSString sizeWithAttributes:] to get the size of a string I get the correct width and I always get 1.0 for the height. I also have an iOS app and this rendering class is used on both iOS and Mac. On iOS when I use a UIFont with a point size of .001 I get the correct height when I call sizeWithAttributes. , I've got the same problem. The following sample code
code :
``````#if TARGET_OS_IOS == 0
#define UIFont NSFont
#define NSStringFromCGSize NSStringFromSize
#endif

UIFont *uiFont = [UIFont fontWithName:@"Courier" size:19];
CGSize boxSize = [@"1" sizeWithAttributes:@{NSFontAttributeName:uiFont}];
NSLog(@"boxSize %@", NSStringFromCGSize(boxSize));
``````
``````CTFontRef _contentFont = CTFontCreateWithName((__bridge CFStringRef)@"Courier", 19, NULL);
CGGlyph glyphs;
UniChar chars;
chars = '1';
bool rc = CTFontGetGlyphsForCharacters(_contentFont, chars, glyphs, 1);
if (rc) {
boxSize.height = CTFontGetAscent(_contentFont) + CTFontGetDescent(_contentFont);
}
`````` ## Generate small cubes on a Plane?

By : user2714544
Date : March 29 2020, 07:55 AM
code :
``````GameObject plane = GameObject.Find("plane");

GameObject obj = Instantiate(prefab, new Vector3(hit.point.x, plane.transform.position.y + cubesize/2, hit.point.z), Quaternion.identity) as GameObject;
`````` ## How to use a vector set point with mpc inorder to give program information on how the future set point will change

By : user3327796
Date : March 29 2020, 07:55 AM
will help you The gekko CV object only uses a scalar value of an array for SP, SPHI, and SPLO so some modification is needed to have the optimizer consider future setpoint changes. A simple MPC application shows how setpoints are used in Gekko.
code :
``````from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.linspace(0,20,41)
p = m.MV(value=0, lb=0, ub=100) # Declare MV
p.STATUS = 1  # allow optimizer to change
p.DCOST = 0.1 # smooth MV response
p.DMAX = 10.0 # max move each cycle
v = m.CV(value=0) # Declare CV
v.STATUS = 1  # add CV to the objective
m.options.CV_TYPE = 2 # squared error
v.SP = 40     # set point
v.TR_INIT = 1 # set point trajectory
v.TAU = 5     # time constant of trajectory
m.Equation(10*v.dt() == -v + 2*p)
m.options.IMODE = 6 # control
m.solve(disp=False)
import json
with open(m.path+'//results.json') as f:
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,results['v1.tr'],'k-',label='Reference Trajectory')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
``````
``````from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.linspace(0,20,41)
p = m.MV(value=0, lb=0, ub=100) # Declare MV
p.STATUS = 1  # allow optimizer to change
p.DCOST = 0.1 # smooth MV response
p.DMAX = 10.0 # max move constraint
v = m.Var(value=0)
sp = np.ones(41)*40
sp[20:] = 60
s = m.Param(value=sp)
m.Obj((s-v)**2)
m.Equation(10*v.dt() == -v + 2*p)
m.options.IMODE = 6 # control
m.solve(disp=False)
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,sp,'k-',label='Setpoint')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
``````
``````from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.linspace(0,20,41)
p = m.MV(value=0, lb=0, ub=100) # Declare MV
p.STATUS = 1  # allow optimizer to change
p.DCOST = 0.1 # smooth MV response
p.DMAX = 10.0 # max move constraint
v = m.Var(value=0)
sp = np.ones(41)*40
sp[20:] = 60
s = m.Param(value=sp)
e = m.CV(value=0) # Declare CV
e.STATUS = 1  # add CV to the objective
m.options.CV_TYPE = 2 # squared error
e.SP = 0     # set point
e.TR_INIT = 1 # error trajectory
e.TAU = 5     # time constant of trajectory
m.Equation(e==s-v)
m.Equation(10*v.dt() == -v + 2*p)
m.options.IMODE = 6 # control
m.solve(disp=False)
plt.figure()
plt.subplot(2,1,1)
plt.plot(m.time,p.value,'b-',label='MV Optimized')
plt.legend()
plt.ylabel('Input')
plt.subplot(2,1,2)
plt.plot(m.time,sp,'k-',label='Setpoint')
plt.plot(m.time,v.value,'r--',label='CV Response')
plt.ylabel('Output')
plt.xlabel('Time')
plt.legend(loc='best')
plt.show()
`````` ## marching cubes, very small triangles

By : hunter
Date : March 29 2020, 07:55 AM
should help you out That's normal for marching cubes. It's a know problem of the algorythm with some technical name like redundant triangles. There is a very simple adjustment for that if you need less triangles and dont mind adding a compare equals line for every vertex, the fix is to snap iso values onto the corners of the cubes if they are more than 95% closer to them. MC optimizations are very cool the best would be octree sensing of used cubes and resizing the cubes relative to the complexity or flatness of the surface at that zone. there are awesome papers on the topic.
Here is a demonstration of a fast fix just by snapping values to corners if edge intersection proximity to corner is under 5% or over 95%, tunable, can try 90% if you want. 