简体   繁体   中英

Fit surface to 3 to 100 points where z values are 3D

I found myself in quite a big problem. I am average in math and I need to solve something, which is not very covered on the internet.

My problem: I have 2D space defined by X and Y. This space is just a drawing space. I want to assign to particular Xs,Ys a color with RGB values.

So let says I have 4 points with defined position in XY and color in Z:

  1. [0,0, [255,0,0]]
  2. [0,10, [0,255,0]]
  3. [10,10,[0,0,255]]
  4. [5,5, [0,0,0]]

and my drawing space is xy: 15x15. And I want to distribute the colors to all empty points

For me its quite a delicate problem, because Z axis is basicly 3D space by itself.

My whole intention is to create a color map in which points 1,2,3,4 have between them smooth transition. I am able to solve this in 1D where the transition is between 2 points. But I need to create 2D color map in XY drawing space based on fitted surface to these 4 points, which kind of depend both on the space of 3D-RGB and distance between them in XY drawing space.

Thanks in advance for help

You do not show any algorithm or code, so I will just explain a high-level algorithm. If you need more details or code or mathematical formulae, show more of your own work then ask. You do not explain just what you mean by "smooth transition"--there are multiple meanings. This will result in continuous shading but may not be smooth enough for your purposes.

First, given your points in the rectangular drawing space, find the Voronoi diagram for those points. This divides the drawing space into convex polygons, each polygon around one of your points.

For each vertex in the Voronoi diagram, figure which points are closest to the vertex--there will usually be just three of your points but there could be more. Then at that vertex point, assign the color that is the average of the RGB values of the nearby given points. That is, average the R values and the G values and the B values separately.

For any point on a Voronoi polygon edge , its color is the weighted average of the two colors at the endpoints. Ie If the point is one-third of the distance from one end, its RGB value is one-third of the distance from the values at the endpoints.

Finally, for any point inside a Voronoi polygon, calculate the ray from the point that defined that polygon (the "center point") through the current point you are looking at. Find where that ray intersects the polygon. The RGB value is then the weighted average of the values of the center point and the polygon-intersection point.

The hardest part of all that is finding the Voronoi diagram. Fortune's algorithm can do this in a reasonable time. You can probably find a library to do that for you in your chosen programming language.


Another algorithm is to start with a triangulation of your given points and the corners of the drawing region. Then the color of any point in a triangle is the weighted average of the colors of the vertices. This will be automatically consistent for points on the vertices or edges of the triangles, so this is probably simpler than my previous algorithm. The difficulty here is finding a triangulation (any will do).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM