ios


Wrong area calculation objective-c?


I have an array with 5 CGPoints (v0, v1, v2, v3, v4) which are the vertex of the shape implemented like this:
_arrayVertex = [[NSMutableArray alloc] initWithObjects:[NSValue valueWithCGPoint:v0], [NSValue valueWithCGPoint:v1], [NSValue valueWithCGPoint:v2], [NSValue valueWithCGPoint:v3], [NSValue valueWithCGPoint:v4], nil];
Then, I calculate the area with those points:
- (float)calculateArea {
float area = 0;
int N = (int)_arrayVertex.count;
for (int i = 0; i < N-1; i++) {
float term = ([_arrayVertex[i] CGPointValue].x * [_arrayVertex[i+1 % N] CGPointValue].y -
[_arrayVertex[i+1 % N] CGPointValue].x * [_arrayVertex[i] CGPointValue].y)/2.0;
area += term;
}
return fabsf(area);
}
Is the area correctly calculated? Am I missing something?. Thank you in advance.
sbim:
- (float)calculateArea {
float area = 0;
int N = (int)_arrayVertex.count;
for (int i = 0; i < N; i++) {
float term = ([_arrayVertex[i] CGPointValue].x * [_arrayVertex[(i+1) % N] CGPointValue].y -
[_arrayVertex[(i+1) % N] CGPointValue].x * [_arrayVertex[i] CGPointValue].y)/2.0;
area += term;
}
return fabsf(area);
}

Related Links

Automatic Login in IOS Swift [closed]
In UILabel, multiple strings with multiple colors for each string?
Swift lazy load property Alamofire request
Drag and launch type thing in Swift Sprite Kit?
Extend navigation bar under status bar in interface building
UIBezierPath: byRoundingCorners: doesn't work
How To Change The Title Color of an MFMailComposeViewController?
Preventing UIImagePicker memory problems
CoreData. Manage multiple coordinators, in multi thread, multi context
AVPlayer(ViewController): can not play HLS HD video
Duplicate symbols for architecture when using global constants [duplicate]
iOS: UIWebView display link from website [duplicate]
In App Purchases returns error
NSAttributedString with image doesn't work in UITextField?
How to generate iPhone simulator build or .zip file for submit in Facebook for review in iOS
Xcode lost connection with simulator iOS 9

Categories

HOME
codeigniter
oozie
magento
music
apt-get
compiler-errors
amazon-kinesis
genetic-algorithm
redhat
box
apple-mail
phpmailer
classloader
apache-spark-sql
windows-10-desktop
avr
group-by
deserialization
export-to-excel
jsqmessagesviewcontroller
teraterm
orientdb-2.1
pydev
pcap
powershell-v2.0
similarity
netlify
datamatrix
netcdf
dsc
effects
android-arrayadapter
arduino-esp8266
shinydashboard
feedly
file-manager
pymysql
whatsapi
angular2-databinding
tensor
webcenter
bcel
runge-kutta
cookiestore
weebly
internet-explorer-10
jpype
textangular
jquery-ui-dialog
free-diameter
msysgit
pci
powerpc
hostapd
rating-system
spring-form
multisite
android-gps
orchestrate
koala-framework
g-wan
view-source
curly-braces
itamae
django-errors
tfs2008
amazon-dynamodb-streams
sql-server-2016-express
strace
egl
document-ready
materialdrawer
session-replication
json4s
chunk-templates
esky
scalariform
textmatching
sigkill
swift-array
words
horizontalscrollview
imake
tortoisecvs
mysql5
laravel-validation
opensc
brooklyn
first-class-functions
controlsfx
mydbr
qt4.7
mod-python
str-to-date
pubdate
progressdialog
virtual-earth
oncreate
libavg
zmodem
payment-services
nntp
retain
stsadm
xlink

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App