So basically programmatically, given 4 3D coordinates for the ceiling of a room as well as 3 pairs of 3D coordinates for the water pipes above the ceiling I am to calculate how many sprinklers I can have in the ceiling if each sprinkler has to be 2500mm from the walls and apart from each other.
I could write out the program but the problem is I don't know how this is calculated.
The problem:
calculate the number of sprinklers, their positions on the room’s ceiling and connect each sprinkler to the nearest water pipe.
The room has a rectangular shape. Ceiling coordinates (x, y, z) are:
(97500.00, 34000.00, 2500.00)
(85647.67, 43193.61, 2500.00)
(91776.75, 51095.16, 2500.00)
(103629.07, 41901.55, 2500.00)
Three water pipes are available:
(98242.11, 36588.29, 3000.00) to (87970.10, 44556.09, 3500.00)
(99774.38, 38563.68, 3500.00) to (89502.37, 46531.47, 3000.00)
(101306.65, 40539.07, 3000.00) to (91034.63, 48506.86, 3000.00)
Sprinklers are to be placed on the ceiling 2500mm away from the walls and from each other.
Please, calculate the number of sprinklers that can be fitted into this room, then calculate
coordinates (x, y, z) of each sprinkler.
For each sprinkler calculate coordinates (x, y, z) of the connection point to the nearest water pipe.
Now I understand that the distance formula between two 3d points is d = sqrt((x2-x1)^2 (y2-y1)^2 (z2-z1)^2)
.
But I'm not sure how to calculate the number of sprinklers using this. or how to calculate their points of intersection on the water pipes. if i could calculate their points of intersection on each pipe and the distance from that point to each sprinkler, then the nearest pipe would be obvious and that would be the pipe the sprinkler connects to.
I have to write this using c# and the dotnet framework. But would I be able to please get some assistance putting this into the form of pseudocode and understanding how to approach, tackle and calculate this problem? I'm not good at the maths side of this but hopefully once understanding how it is solved, I can then possibly put this into a c# function.
CodePudding user response:
This question is so elaborated that, even in pseudocode, it's a big deal.
You might start with a re-calibration of your rectangle (indeed, the four coordinates you provide form a rectangle indeed): you shift your entire rectangle so that one point equals (0,0). The you rotate your rectangle in order for your rectangle to have following coordinates:
(0,0)
(Xmax, 0)
(0, Ymax)
(Xmax, Ymax)
Once you have this, you can start looking for your algorithm for filling the ceiling with sprinklers. First you can base yourself on this "algorithm":
- Fill your rectangle with squares where the length of the line equals two times the given radius.
Once you have this, you can upgrade to the following "algorithm":
- Fill your rectangle with circles with the given radius.
Revert everything to the original coordinates (rotating back and shifting back).
Once you have this, you might start calculating the distances to the pipes, using basic "distance-between-point-and-line" formula.
CodePudding user response:
Notice that the ceiling can be tiled with 4x6 squares of side 2500 mm. That tells you the number of sprinklers.
You can find their positions by computing vectors of length 2500 mm, parallel to the sides (first compute unit vectors). It is not too difficult to obtain then coordinates using a matrix arrangement.
Next, you compute the distance of every sprinkler to the three pipes and keep the shortest. (CAUTION: distance to the line segments, not to the lines of support.)