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

Material Select blinking on iOS
How to get the Core data Primary key value in ios Swift? [duplicate]
How to remove only minutes from UIDatePickerMode.DateAndTime
UIButton click causing app freeze/Rapid increase in memory
libobjc.A.dylib objc_msgSend crash occurring with core data usage in background thread
Disabling Dynamic Type in Swift
how to make overlay with activity indicator programatically
performseguewithidentifier works with a delay
Type [TeamModel] has no subscript members
Pdf file in webview not scrolling
Ternary Conditional Operator for nil/not nil
Xamarin / IOS / Azure - No 'id' member found on type
iOS 9 core location crash
Better accessibility label for a clickable table view cell
iOS add fixed footer UIView to multiscreen app
how to send data from iOS prototype cell to watch with swift 2.2

Categories

HOME
flutter
validation
oozie
ssl-certificate
anylogic
quickblox
libreoffice
svg.js
antlr4
visual-studio-2012
geany
google-analytics-api
telerik
wget
py.test
google-maps-sdk-ios
export-to-excel
servlet-filters
rational
teamcity-9.0
ghost-blog
sencha-touch-2
profiling
naturallyspeaking
nested-loops
flexjs
meanjs
svn2git
matterjs
tensor
advanced-installer
bcel
packaging
json-rpc
amazon-elasticsearch
internet-explorer-10
angularjs-routing
win2d
slt
android-calendar
ssms-2012
xbrl
okular
dump
ios-app-group
mspgcc
masm32
cmsmadesimple
qtcpserver
mapr
ipmi
dr-memory
mailcore2
topojson
perspective
xendesktop
texture2d
finalcut
pager
ios-frameworks
bash-completion
webpack-hmr
mars
okuma
pakyow
occam-pi
tag-helpers
metalkit
kinto
ssha
materialdrawer
text-alignment
tun
python-2.3
spl
nominatim
cocoon-gem
protected
devenv
cordova-cli
fortrabbit
llvm-gcc
android-tablelayout
applicationstate
mysql5
typesafe-activator
iphone-privateapi
bunny
bonecp
hobbitmon
libtorrent-rasterbar
location-client
glulookat
libnids
memoization
geometry-surface
mosek
angularjs-module
self-organizing-maps
ondraw
gemstone
process.start
postgresql-8.1
mate
xmltextwriter
staging
.net-1.1
android-3.1
sqlprofileprovider
greensoftware

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