Get area surface and ceiling height with RoomPlan - ios

Can't see it it the doc but, do you know/think it's possible to get the surface of a room in square meter and the ceiling heigh in meter ? Thanks

let length = 4.0 // Length of the room in meters
let width = 5.0 // Width of the room in meters
let height = 2.5 // Height of the room in meters
let surfaceArea = length * width * height
let ceilingHeight = height
print("The surface area of the room is \(surfaceArea) square meters.")
print("The height of the ceiling is \(ceilingHeight) meters.")

Related

Minimal zoom level CameraZoomRange doesn't work correctly

I try to set minimal and maximal zoom level in MKMapView.
When I set minimal zoom range it doesn't work correctly. For minCenterCoordinateDistance: 500 diameter seems to be 163 meters (checked with google maps and by drawing circle with MapKit). Also when I change aspect ration of the mapView the diameter value is different.
Can someone explain it to me?
I will be grateful.
mapView.cameraZoomRange = MKMapView.CameraZoomRange(
minCenterCoordinateDistance: 500,
maxCenterCoordinateDistance: 5000
)
------------- update ------------
Temporary solution:
var ratio = mapSize.height / mapSize.width
ratio = max(ratio, 1) * 1.88
let maxValue = maxCameraDistance * ratio
let minValue = minCameraDistance * ratio
mapView.cameraZoomRange = MKMapView.CameraZoomRange(
minCenterCoordinateDistance: minValue,
maxCenterCoordinateDistance: maxValue
)
But why magic number is 1.88 ?

Check if user's input number is positive or negative, and give error it it is negative

I am trying to create a program that takes the user's input width and height and outputs area and perimeter of a rectangle. I also want the program to check if the user puts a positive or negative value for either the width or height. If the user puts in a negative value for either I want it to display an error. This is what I have so far but it kinda just skips passed and still calculates.
local width, height, area, perimeter
-- intro text and user inputs
print("Welcome to the Rectangle Area & Perimeter Calculator")
print("Enter Rectangle Width")
width = io.read("n")
if width <0
then print "Error: Please enter a positive value for width"
end
print("Enter Rectangle Height")
height = io.read("n")
if height <0
then print "Error: Please enter a positive value for height"
end
--Calculator
area = width * height
print("The area of the rectangle is ", area)
perimeter = 2 * (width + height)
print("The perimeter of the rectangle is ", perimeter)
Edit 2 : you can use repeat until loop for this , so the block of code will be repeated until the user input number is positive , try below code
local width, height, area, perimeter
-- intro text and user inputs
print("Welcome to the Rectangle Area & Perimeter Calculator")
repeat
print("Enter Rectangle Width")
width = io.read("n")
if(width < 0)
then print("error : enter a positive value")
end
until width > 0
repeat
print("Enter Rectangle Height")
height = io.read("n")
if height <0
then print "Error: Please enter a positive value for height"
end
until height > 0
--Calculator
area = width * height
print("The area of the rectangle is ", area)
perimeter = 2 * (width + height)
print("The perimeter of the rectangle is ", perimeter)

Empty space at the top of the screen Corona sdk

I am new in Corona SDK and I have a problem,
when I place an image at the top of the screen, there is an empty space, how can I make it disappear?
thanks!
It all depends on which device you are running an app. Some of them are taller, some are wider. So there's a value display.screenOriginY which has to be added to a y value if you place an object in a distance from top of screen.
Here's more info:
https://docs.coronalabs.com/api/library/display/screenOriginY.html
In your config.lua file, you can make Corona fill the entire device screen by setting scale = "adaptive". You can read more about adaptive content scaling here
When you use this adaptive scaling, the coordinate (0,0) will be the upper left of the device screen. However, the width and height will vary from device to device and you have to take this into account in your code. You can get these parameters using display.contentWidth and display.contentHeight.
Try (point (0, 0) is located in upper top corner od screen)
--calculate the aspect ratio of the device
local aspectRatio = display.pixelHeight / display.pixelWidth
application = {
content = {
width = aspectRatio >= 1.5 and 800 or math.floor( 1200 / aspectRatio ),
height = aspectRatio <= 1.5 and 1200 or math.floor( 800 * aspectRatio ),
scale = "letterBox",
fps = 30,
imageSuffix = {
["#2x"] = 1.3,
},
},
}

Calculate real width based on picture, knowing distance

I know the distance between the camera and the object
I know the type of camera used
I know the width in pixel on the picture
Can I figure the real life width of the object?
you have to get the angle of camera. For example, iphone 5s is 61.4 in vertical and 48.0 horizontal. call it alpha.
then you calculate the width of object by this way:
viewWidth = distance * tan(alpha / 2) * 2;
objWidth = viewWidth * (imageWidth / screenWidth)

convertCoordinate toPointToView returning bad results with tilted maps

I have a UIView overlayed on a map, and I'm drawing some graphics in screen space between two of the coordinates using
- (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate toPointToView:(UIView *)view
The problem is that when the map is very zoomed in and tilted (3D-like), the pixel position of the coordinate that is way off-screen stops being consistent. Sometimes the function returns NaN, sometimes it returns the right number and others it jumps to the other side of the screen.
Not sure how can I explain it better. Has anyone run into this?
During research have find a many solution. Any solution might be work for you.
Solution:1
int x = (int) ((MAP_WIDTH/360.0) * (180 + lon));
int y = (int) ((MAP_HEIGHT/180.0) * (90 - lat));
Solution:2
func addLocation(coordinate: CLLocationCoordinate2D)
{
// max MKMapPoint values
let maxY = Double(267995781)
let maxX = Double(268435456)
let mapPoint = MKMapPointForCoordinate(coordinate)
let normalizatePointX = CGFloat(mapPoint.x / maxX)
let normalizatePointY = CGFloat(mapPoint.y / maxY)
print(normalizatePointX)
print(normalizatePointX)
}
Solutuin:3
x = (total width of image in px) * (180 + latitude) / 360
y = (total height of image in px) * (90 - longitude) / 180
note: when using negative longitude of latitude make sure to add or subtract the negative number i.e. +(-92) or -(-35) which would actually be -92 and +35

Resources