2016-04-25 60 views
0

我正在做一个笔记写应用程序。在这个应用程序中,我将曲线变成贝塞尔曲线。此刻,当我尝试将新值添加到在while循环之外定义的矩阵中时出现错误。当我把它放到一个虚拟变量中并且它在循环中工作时,我已经尝试了这个表达式。当我使用格式来替换两维变量的值时,它在循环外部工作,但是,当我在循环中同时执行这些操作时,它不起作用。swift-在while循环中使用数组值替换exc_bad_instruction(code = exc_i386_invop,subcode = 0x0)

//: Playground - noun: a place where people can play 

import UIKit 


var x2 = 6.0 
var y2 = 5.0 
var x1 = 1.0 
var y1 = 1.0 

var p1x = 2.0 
var p1y = 3.0 

var B = 6.5 
var Ba = 2.2 
var percentall = Ba/B 

var yall = 5.0 
var xall = 1.0 
var A = 4.0 
var C = 5.0 
var Ct = 0.0 
var At = 0.0 
var Aall = Int(A) * 10 
var Call = Int(C) * 10 


var thelistx = [[Double]](count: Call, repeatedValue: [Double](count: Call, repeatedValue: 0.0)) 
var thelisty = Array(count: Aall, repeatedValue: Array(count: Call, repeatedValue: 0.0)) 


var theAt = 0 
var theCt = 0 


while At <= A { 
    var Apercent = percentall * At 
    var Aend = y1 + At 
    var yslope = (A - At) * percentall + Aend 
    var lefty = (yslope - Apercent) * percentall + Apercent 
    var righty = (y2 - yslope) * percentall + yslope 
    while Ct <= C { 
     var Cpercent = percentall * Ct 
     var Cend = x2 - Ct 
     var xslope = (C - Ct) * percentall + Cend 
     var leftx = (xslope - x1) * percentall + x1 
     var rightx = (x2 - xslope) * percentall + xslope 

     thelistx [theAt] [theCt] = (rightx - leftx) * percentall + left 

*********************Execution was interrupted, reason exc_bad_instruction (code=exc_i386_invop, subcode=0x0) *************** 

     thelisty [theAt] [theCt] = (righty - lefty) * percentall + lefty 

     Ct += 0.1 
     theCt += 1 
    } 
    At = At + 0.1 
    theAt += 1 
} 

回答

1

控制台显示你的错误是什么:

fatal error: Index out of range

你要出界与thelistx [theAt] [theCt]

更改while Ct < CCt < C - 1保持在数组的边界您的来电。

相关问题