我有一个带有这个参数的画布:
public class Owner : Entity<Owner>
{
...
}
public class Car : Entity<Car>
{
...
}
public abstract class Entity<T> : IEntity
where T: IEntity
{
public long Id { get; }
public static Repository<Entity<T>> CurrentRepository { get; set; }
static Entity()
{
CurrentRepository = new Repository<Entity<T>>();
}
public Entity()
{
}
public void Save()
{
CurrentRepository.Save(this);
}
public void Delete()
{
CurrentRepository.Delete(this);
}
}
,//cube
//when dimension is 0.1 everything is fine
float dimension = 0.05;
SCNBox *cube = [SCNBox boxWithWidth:dimension height:dimension length:dimension chamferRadius:0];
cube.materials = @[material];
SCNNode *node = [SCNNode nodeWithGeometry:cube];
node.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeDynamic shape:nil];
node.physicsBody.mass = 1;
node.physicsBody.categoryBitMask = phsicBodyCategoryCube;
node.physicsBody.collisionBitMask = phsicBodyCategoryPlane;
node.physicsBody.contactTestBitMask = phsicBodyCategoryPlane;
//plane
self.planeGeometry = [SCNBox boxWithWidth:100 height:0.01 length:100 chamferRadius:0
plane.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeKinematic
shape: [SCNPhysicsShape shapeWithGeometry:self.planeGeometry options:nil]];
plane.physicsBody.categoryBitMask = phsicBodyCategoryPlane;
plane.physicsBody.collisionBitMask = phsicBodyCategoryCube;
plane.physicsBody.contactTestBitMask = phsicBodyCategoryCube;
并以width = 400
的角度(以度为单位)穿过点height = 400
我需要获取平面中线条交点的所有坐标并将其写入数组。现在我使用这个等式:cursor[x1,y1]
检查我使用此代码的所有点:
var rad = Q * Math.PI / 180;
Q
例如,当0&lt; Q&lt; 90和光标[x1,y1] = [200,200] z.length = 0并且它不正确。
我哪里错了?也许有更方便的算法?
P.S。对不起我的英文
答案 0 :(得分:0)
我想象一个这样的算法。 (我只考虑0&lt; Q&lt; 90时的情况)。首先,我想计算线与Ox和Oy轴相交的点,考虑左上角的原点(0,0),如果我们想象负x和y值分别在左边和这一点的顶部。设x2
和y2
为线与Ox和Oy相交的值。我们想要计算这些值。我们现在有一个包含2个未知变量(x2和y2)的系统:Math.tan(rad) = (y1 -y2)/x1
和Math.tan(rad) = y1/(x1-x2)
。我们可以通过在坐标系上绘制线并分析一下来推导出这些方程。如果我们求解方程组,我们会发现类似:x2 = (x1*y1 -x1 * x1 * Math.tan(rad)/(2 * y1-x1))
和y2= y1- x1 * Math.tan(rad)
(这些需要验证,我没有仔细检查过我的微积分)。线性方程可以由公式y = a*x + b
定义,在我们的例子中由a = x2
和b = y2
定义。然后我们可以像这样计算点数:
for (xIdx = 0; xIdx < 400; xIdx += 1) {
var ctrX = xIdx;
var ctrY = x2 * ctrX + y2 //todo: replace with the respective calculated variables x2 and y2(we could also define two functions in js) and proper rounding
z.push([ctrX, ctrY]);
}
我不确定我是否100%准确但我希望你理解我的想法。
答案 1 :(得分:0)