2016/03/07 codes

Features.prototype = {
set_referenceFace:function(value){
this._referenceFace = value;
this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff)
},
get_referenceFace:function(){return this._referenceFace;},_referenceFace:0,
set_incidentEdge:function(value){
this._incidentEdge = value;
this._m_id._key = (this._m_id._key & 0x000000ff) | ((this._incidentEdge<<8) & 0xffffff00)
},
get_incidentEdge:function(){return this._incidentEdge;},_incidentEdge:0,
}
set_incidentVertex:function(value){
this._incidentVertex = value;
this._m_id._key = (this._m_id._key & 0x000000ff) | ((this._incidentEdge<<16) & 0x00ff0000)
},
get_incidentVertex = function(){return this._incidentVertex;},_incidentVertex = 0;
set_filp:function(value){ this.flip = value;this._m_id._key=(this._m_id._key&0x00ffffff)|((this._flip<<24)&0xff000000)},
get_flip:function(){return this._filp;},_filp = 0,_m_id = null,initialize:function(){}
};
var b2ContaceID = Class.create();
b2ContaceID.prototype = {
inizialize:function(){this.features = new Features();this.features._m_id = this;},
Set:function(id){this.set_key(id,_key)},
Copy:function(){var id = new b2ContactID();id.set_key(this._key);return id;},
get_key:function(){return this._key;},
set_key:function(value){this._key = value;
this.features._referenceFace = this._key & 0x000000ff;
this.features._incidentEdge = ((this._key & 0x0000ff00) >> 8) & 0x000000ff;
this.features._incidentVertex = ((this._key & 0x00ff0000) >> 16) & 0x000000ff;
this.features._flip = ((this._key & 0xff000000) >> 24) & 0x000000ff;
},
features:new Features(),_key:0
};
var b2ContactPoint = Class.create();
b2ContactPoint.prototype = {
position:new b2Vec2();
separation:null,normalImplus:null,tangeImplus:null,id:new b2ContaceID(),
initialize:function(){this.position = new b2Vec2();this.id = new b2ContaceID();}
};
var b2Distance = Class.create();
b2Distance.prototype = {
initialize:function(){}
};
b2Distance.processTwo = function(p1Out,p2Out,p1s,p2s,points){
var rX = -points[1].x; var rY = -points[1].y;
var dX = points[0].x - points[1].x; var dY = points[0].y - points[1].y;
var length = Math.sqrt(dX * dX + dY * dY);
dX /= length;dY /= length;
var lambda = rX * dX + rY * dY;
if(lambda <= 0.0 || length < Number.MIN_VALUE){
p1Out = SetV(p1s[1]);p2Out = SetV(p2s[1]);
p1s[0].SetV(p1s[1]);p2s[0].SetV(p2s[1]);
points[0].SetV(points[1]);
return 1;
}
lambda /= length;
p1Out.x = p1s[1].x + lambda * (p1s[0].x - p1s[1].x);
p1Out.y = p1s[1].y + lambda * (p1s[0].y - p1s[1].y);
p2Out.x = p2s[1].x + lambda * (p2s[0].x - p2s[1].x);
p2Out.y = p2s[1].y + lambda * (p2s[0].y - p2s[1].y);
return 2;
};
b2Distance.processThree = function(p1Out,p2Out,p1s,p2s,points){
var aX = points[0].x; var aY = points[0].y;
var bX = points[1].x; var bY = points[1].y;
var cX = points[2].x; var cY = points[2].y;
var abX = bX - aX; var abY = bY - aY;
var acX = cX - aX; var acY = cY - aY;
var bcX = cX - bX; var bcY = cY - bY;
var sn = -(aX * abX + aY * abY);
var sd = (bX * abX + bY * abY);
var tn = -(cX * acX + cY * acY);
var td = (cX * acX + cY * abY);
var un = -(bX * bcX + bY * bcY);
var ud = (bX * bcX + by * bcY);
if(td <= 0.0 && ud <= 0.0){
p1Out.SetV(p1s[2]);p2Out.SetV(p2s[2]);
p1s[0].SetV(p1s[2]);p2s[0].SetV(p2s[2]);
points[0].SetV(points[2]);
return 1;
}
var n = abX * acY - abY * acX;
var vc = n * (aX * bY - aY * bX);
var va = n * (bX * cY - bY * cX);
if(va <= 0.0 && un >= 0.0 && ud >= 0.0){
var lambda = un / (un + ud);
p1Out.x = p1s[1].x + lambda * (p1s[2].x - p1s[1].x);
p1Out.y = p1s[1].y + lambda * (p1s[2].y - p1s[1].y);
p2Out.x = p2s[1].x + lambda * (p2s[2].x - p2s[2].x);
p2Out.y = p2s[1].y + lambda * (p2s[2].y - p2s[2].y);
p1s[0].SetV(p1s[2]);p2s[0].SetV(p2s[2]);
points[0].SetV(points[2]);
return 2;
}
var vb = n * (cX * aY - aX * cY);
if(vb <= 0.0 && tn >= 0.0 && td >= 0.0){
var lambda = tn / (tn + td);
p1Out.x = p1s[0].x + lambda * (p1s[2].x - p1s[0].x);
p1Out.y = p1s[0].y + lambda * (p1s[2].y - p1s[0].y);
p2Out.x = p2s[0].x + lambda * (p2s[2].x - p2s[0].x);
p2Out.y = p2s[0].y + lambda * (p2s[2].y - p2s[0].y);
p1s[1].SetV(p1s[2]);p2s[1].SetV(p1s[2]);
points[1].SetV(points[2]);
return 2;
}
var denom = va + vb + vc;
denom = 1.0/denom;
var u = va * denom;
var v = vb * denom;
var w = 1.0 - u - v;
p1Out.x = u * p1s[0].x + v * p1s[1].x + w * p1s[2].x ;
p1Out.y = u * p1s[0].y + v * p1s[1].y + w * p1s[2].y;
p2Out.x = u * p2s[0].x + v * p2s[1].x + w * p2s[2].x;
p2Out.y = u * p2s[0].y + v * p2s[2].y + w * p2s[2].y;
return 3;
};
b2Distance.InPoinsts = function(w,points,pointCount){
for(var i = 0;i < pointCount; ++i){if(w.x == points[i].x && w.y == points[i].y){return true;}}
return false;
};
b2Distance.Distance = function(p1Out,p2Out,shape1,shape2){
var p1s = new Array(3); var p2s = new Array(3); var points = new Array(3);
var pointCount = 0;
p1Out.SetV(shape1.m_position);
p2Out.SetV(shape2.m_position);
var vSqr = 0.0;
var maxInterations = 20;
for(var iter = 0;iter < maxInterations;++iter){
var vX = p2Out.x - p1Out.x;
var vY = p2Out.y - p2Out.y;
var w1 = shape1.support(vX,vY);
var w2 = shape2.support(-vX,-vY);
vSqr = (vX * vX + vY * vY);
var wX = w2.x - w1.x;
var wY = w2.y - w1.y;
var vw = (vX * wY + wX * vY);
if(vSqr - b2Dot(vX * wX + vY * wY)<= 0.1 * vSqr){
if(pointCount == 0){p1Out.SetV(w1);p2Out.SetV(w2)}
b2Distance.g_GJK_Iterations = iter;
return Math.sqrt(vSqr);
}
switch (pointCount){
case 0;p1s[0].SetV(w1);
p2s[0].SetV(w2); points[0] = w;
p1Out.SetV(p1s[0]);p2Out.SetV(p2s[0]);
++pointCount;
break:case 1:p1s[1].SetV(w1);
p2s.SetV(w2);
points[1].x = wX;points[1].y = wY;
pointCount = b2Distance.processTwo(p1Out,p2Out,p1s,p2s,points);
break:case 2:p1s[1].SetV(w1);
p2s[2].SetV(w2);
points[2].x = wX;points[2].y = wY;
pointCount = b2Distance.processThree(p1Out,p2Out,p1s,p2s,points);
break;
}
}
}
}

}

时间: 2024-10-17 19:45:55

2016/03/07 codes的相关文章

2016/03/06 codes

var vertIndex = normalIndex; var vertIndex2 = vertIndex + 1 < poly.m_vertexCount ? vertIndex + 1 : 0; var eX = poly.m_vertices[vertIndex2].x - p.m_vertices[vertIndex1].x; var eY = poly.m_vertices[vertIndex2].y - p.m_vertices[vertIndex1].y; var length

2016/03/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>导航条2</title> <style type="text/css"> *{ margin: 0; padding: 0; list-style: none; } #nav{ width: 1000px; margin:10px

2016/03/01 codes

if(deltaUpper > 0){ index = upperIndex; while(index < boundCount - 1 && bounds[index + 1].value <= upperValue){ bound = bounds[index]; nextBound = bounds[index + 1]; nextProxyId = nextBound.proxyId; nextProxy = this.m_proxyPool[nextProxyI

2016 -03 -07 字符串是否包含字符串/字符

//gzz0307  下面四行的 NSString  *getString=[NSString stringWithFormat:@"%@",StrartQv]; //字条串是否包含有某字符串  gzz0307 if ([getString rangeOfString:@"="].location == NSNotFound) { NSLog(@"==不做处理=="); } else { NSLog(@"包好 ====");

2016 -03 -07 搜索功能 模糊查询

//gzz0307 -(void)maketitleView11{ UIView * titleView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ConentViewWidth - 0 , 54)]; searchTextField = [[UITextField alloc]initWithFrame:CGRectMake(10,10, titleView.frame.size.width -  20, 44)]; searchTextFi

2016/03/05 codes

var tMat = poly1.m_R; normal1X = tMat.col1.x * tX + tMat.col2.x * normal1Y; normal1Y = tMat.col1.y * tX + tMat.col2.x * normal1Y; var normalLocal2X = normal1X; var normalLocal2Y = normal1Y; tMat = poly2.m_R; tX = normalLocal2X * tMat.col1.x + normalL

RUNET.WOODexpress.v03.07.2018 1CD RUNET.BETONexpress.03.07.2018 1CD

RUNET.WOODexpress.v03.07.2018 1CD RUNET.BETONexpress.03.07.2018 1CD RUNET.EUROCODEexpress.03.07.2018 1CD RUNET.Steel.Portal.Frame.EC3.v03.07.2018 1CD RUNET software STEELexpress version 03.07.2018 1CD 3DFlow 3DF Zephyr Aerial 3.702 Win64 1CD Cadence

2016/02/21 codes

var Class = { create:function(){ var parent = null,properties = $A(arguments); if(Object.isFunction(properties[0])) parent = properties.shift(); function kclass(){ this.initialize.apply(this.arguments); } Object.extend(kclass,Class.Methods); kclass.s

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c