within() method in HibernateSpatial API is checking one way of Geometry, How to make it for two way? - hibernate-spatial

I am using Hibernate Spatial API to check a point Inside \ Outside a Polygon.But it is not helping my Usecase.
As per my usecase, I am having a Polygon shape in my db. *Need to check a Point is inside
/ outside a stored polygon or not *
Point(Geometry) is my Input.
Polygon(Geometry) is stored in my database.
Everytime I have to check the Input with my Stored Polygon.
By the within() method (HibernateSpatial API - NOT MySQL method), I could able to pass the Point(Geometry). But the method is checking against my usecase.
within method is checking the point containing a polygon or not. So I
am getting wrong result in my usecase. See their documentation for reference.
* An implication of the definition is that
* "The boundary of a Geometry is not within the Geometry".
* In other words, if a geometry A is a subset of
* the points in the boundary of a geomtry B, <code>A.within(B) = false</code>
*
*#param g the <code>Geometry</code> with which to compare this <code>Geometry</code>
*#return <code>true</code> if this <code>Geometry</code> is within
* <code>other</code>
*
* #see Geometry#contains
*/
public boolean within(Geometry g) {
return g.contains(this);
}
How to check the polygon inside or outside with Point in HibernateSpatial API. Any help is much appreciated.

To achieve to check other way. Need to implement another method.The method is following
contains(Geometry G)
Documentation clearly says this.

Related

Handle missing values with Stats Models Local Linear Trend model

I am using statsmodels to fit a Local Linear Trend state space model which inherits from the sm.tsa.statespace.MLEModel class using the code from the example in the documentation:
https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_local_linear_trend.html
The state space model and Kalman filter should handle missing values naturally but when I add some null values the state space model outputs nulls. In another example in the docs, implementing SARIMAX it appears that missing data appears to be handled automatically:
https://www.statsmodels.org/dev/examples/notebooks/generated/statespace_sarimax_internet.html
Is there a way to handle missing values in the same way for a Local Linear Trend model?
Chad Fulton replied to the issue I raised on github:
https://github.com/statsmodels/statsmodels/issues/7684
The statespace models can indeed handle NaN values in the endog variable. I think the issue is that in this example code, the starting parameters are computed as:
#property
def start_params(self):
return [np.std(self.endog)]*3
To handle NaN values in the data, you'd want to replace this with:
#property
def start_params(self):
return [np.nanstd(self.endog)]*3
This worked.

Pymunk body-specific damping

How to use pymunk.Body.update_velocity(body, gravity, damping, dt) to dampen the mass. I know I can use global damping here but I want to add more masses later on and have custom damping for each one, and so I want to learn how to deploy body-specific damping. I have the following questions
How to use pymunk.Body.update_velocity
Can I leave gravity blank if I don't want custom gravity. Or should I just write space.gravity
What is dt here and how do I determine that
Did you find the example in the documentation here: http://www.pymunk.org/en/latest/pymunk.html#pymunk.Body.velocity_func ?
You need to define a custom velocity function somewhere, and then set it on the body you want it. So preferably you define it before you create the bodies. In this function you can call the existing default velocity function (pymunk.Body.update_velocity) if you want, but that is not a requirement. It depends on if you want to write all code to update velocity of the body yourself, or if you want to just modify it a bit with the existing code as a base. Since you only want to modify the damping I think its easiest to call the default function.
When you call the default v function you can send in the same gravity unmodified as you get it in your custom function.
dt is the delta time. I see now the docs could be improved here, I will make a note. So the dt is the same value as the dt sent to space.step(dt) function in your simulation loop.
All in all, I think something like this would do (you just need to adjust the calculation of modified_damping to the logic you want):
def custom_damping(body, gravity, damping, dt):
modified_damping = body.custom_damping * damping
pymunk.Body.update_velocity(body, gravity, modified_damping, dt)
body.custom_damping = 0.31415
body.velocity_func = custom_damping
(if you dont want to set a variable on the body you can of course do it in some other way. Lets say you want all bodies to have 2x the damping compared to normal you could do modified_damping = 2 * damping instead, and remove the body.custom_damping property.

Game maker collisions only work sometimes

This is my code for the enemies in my game
//Collision
if (place_meeting(x,y,Object_Wall))
{
speed = 0
direction = point_direction(x,y,Object_Wall.x,Object_Wall.y) + random_range(160,200)
speed = sp / 2
time = random_range(room_speed * 0.75,room_speed * 3)
}
When the zombie hits a wall, it should turn back and walk the other way.
This works most of the time but sometimes they will just drift through walls and if they are following the player and he goes next to a wall they go through it.
I don't know why it doesn't work sometimes and would like help to fix this.
I am using Object_Wallas a parent object and they work with it but the problem occurs with it's children.
When you use point_direction(x,y,Object_Wall.x,Object_Wall.y), it's not object which was found using place_meeting(x,y,Object_Wall).
place_meeting(x,y,Object_Wall) will check collsion with all instances of object Object_Wall. But when you use in point_direction object id instead instance id, GM will take first (in creation order) instance of object Object_Wall.
You can take instance id using, for example, collision_circle function.
But I recommend use Collision event and other keyword inside it.

Get which vertex of a feature is modified

I was trying to get which vertex of a Feature has been modified. It seems that featuremodified event does not supply this information.
this is important because I will have to post the modification to the server. I dont want to post the whole feature object because of one single vertex change.
I am using OpenLayers v2.13.1
You need to hook into the vertexmodified callback of OpenLayers.Layer.Vector. This is triggered by the dragVertex function of OpenLayers.Control.ModifyFeature, see line 479 here http://trac.osgeo.org/openlayers/browser/trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
The vertexmodified function receives a vertex, a feature and a pixel, so you would write something like this, assuming an OpenLayers.Layer.Vector called vector:
vector.events.register('vertexmodified', this, function(vertex, feature, pixel){
//do something with the vertex
});

Palm rotation in LeapJS

I wonder how could I get the correct palm rotation angle (along Y-axis) from Leap Motion (I'm using the latest LeapJS API)?
I have tried both rotationAngle(sinceFrame) method and the frame._rotation. However, the rotationAngle() returns a very small value close to 0, which seems to be the rotation angle calculated based on the current frame (how to define the sinceFrame in Leap.loop(function(frame)){}, as it seems only records data from current frame).
And the frame._rotation returns a 3*3 matrix (which I've no idea about what is it, as it's not included in the API documentation). Therefore, I wonder if there's any way to get the correct rotation angle of Y-axis from these methods?
The latest version of the leap.js library includes a roll() function as a member of the Hand object. (It also has pitch() and yaw(), if roll() isn't all you want.) The roll() function is defined as:
Hand.prototype.roll = function() {
return Math.atan2(this.palmNormal[0], -this.palmNormal[1]);
}
As an aside, since you don't need to use rotationAngle() to get the current palm angles, the rotationAngle() function gives you the rotation that has occurred between two frames. For sinceFrame, you can either store a reference to the starting frame or get a past frame from the history buffer maintained by the Controller object. Although the Leap.loop() function doesn't give you access to its Controller object directly, you should be able to create your own. Note that frame._rotation is an internal variable that is used in the calculation of the transformations between two frames. It isn't much use on its own.

Resources