offset surface
时间: 2024-06-16 14:07:34 浏览: 16
偏移曲面(Offset Surface)是计算机图形学中的一个概念,它是通过在给定曲面的每个点上平移一定距离来生成一个新的曲面。这个平移距离可以是正数、负数或零,从而使得生成的曲面可以向内或向外偏移。
偏移曲面在计算机图形学中有广泛的应用,例如在建模和造型中用于创建实体物体的厚度,或者用于创建曲面的变形效果。它可以用于生成平滑的曲面、创建实体模型的壳体、生成字体和标志的立体效果等。
实现偏移曲面的方法有很多种,其中一种常见的方法是通过计算每个点的法向量,并将该点沿着法向量方向平移一定距离。这样可以保持曲面的整体形状,并生成一个与原曲面相似但具有一定偏移的新曲面。
相关问题
extern UFUNEXPORT int UF_MODL_ask_face_data( tag_t face ,/* <I> Face obj_id / int * type ,/ <O> Face type is NX surface type code 16 = cylinder 17 = cone 18 = sphere 19 = revolved (toroidal) 20 = extruded 22 = bounded plane 23 = fillet (blend) 43 = b-surface 65 = offset surface 66 = foreign surface / double point[] ,/ <O,len:3> Point information is returned according to the value of type as follows. Plane = Position in plane Cylinder= Position on axis Cone = Position on axis Sphere = Center position Torus = Center position Revolved = Position on axis / double dir[] ,/ <O,len:3> Direction information is returned according to the value of type as follows. Plane = Normal direction Cylinder= Axis direction Cone = Axis direction Torus = Axis direction Revolved = Axis direction / double box[] ,/ <O,len:6> Face boundary. The coordinates of the opposite corners of a rectangular box with sides parallel to X, Y, and Z axes (Absolute Coordinate System) are returned. The box contains the specified face and is usually close to the minimum possible size, but this is not guaranteed. box[0] = Xmin box[1] = Ymin box[2] = Zmin box[3] = Xmax box[4] = Ymax box[5] = Zmax / double * radius ,/ <O> Face major radius: For a cone, the radius is taken at the point[3] position on the axis. For a torus, the radius is taken at the major axis. / double * rad_data ,/ <O> Face minor radius: only a torus or cone has rad_data as a minor radius. For a cone, rad_data is the half angle in radians. For a torus, rad_data is taken at the minor axis. / int * norm_dir / <O> Face normal direction: +1 if the face normal is in the same direction as the surface normal (cross product of the U- and V-derivative vectors), -1 if reversed. */ ); 详解
`UF_MODL_ask_face_data` 函数是 UG/Open C API 中的一个函数,用于查询面(face)的数据。以下是该函数的详细解释:
函数原型:
```c
extern UFUNEXPORT int UF_MODL_ask_face_data(
tag_t face, /* <I> 面对象的 ID */
int *type, /* <O> 面的类型,NX 表面类型代码 16 = 圆柱体,17 = 圆锥体,18 = 球体,19 = 旋转体(环形),20 = 挤出体,22 = 平面,23 = 圆弧,43 = B 曲面,65 = 偏移曲面,66 = 外部曲面 */
double point[], /* <O,len:3> 根据类型返回点信息,具体如下:平面=平面上的位置,圆柱体=轴上的位置,圆锥体=轴上的位置,球体=中心位置,旋转体=轴上的位置 */
double dir[], /* <O,len:3> 根据类型返回方向信息,具体如下:平面=法线方向,圆柱体=轴向,圆锥体=轴向,旋转体=轴向 */
double box[], /* <O,len:6> 面边界,返回一个矩形盒子的对角线上的两个点的坐标(参考绝对坐标系),盒子包含了指定的面并且通常是最小可能的,但是不能保证。 */
double *radius, /* <O> 面的主要半径:对于圆锥体,半径是在轴上的点[3]处取的。对于环体,半径是在主轴上取的。 */
double *rad_data, /* <O> 面的次要半径:只有环体或圆锥体具有 rad_data 作为次要半径。对于圆锥体,rad_data 是半角的一半,对于环体,rad_data 是在副轴上取的。 */
int *norm_dir /* <O> 面的法线方向:+1 表示面法线与曲面法线(U- 和 V- 导数向量的叉积)相同,-1 表示相反。 */
);
```
参数说明:
- `face`:要查询的面对象的 ID。
- `type`:返回该面的类型,NX 表面类型代码。
- `point[]`:根据类型返回点信息。具体如下:
- 平面:平面上的位置。
- 圆柱体:轴上的位置。
- 圆锥体:轴上的位置。
- 球体:中心位置。
- 旋转体:轴上的位置。
- `dir[]`:根据类型返回方向信息。具体如下:
- 平面:法线方向。
- 圆柱体:轴向。
- 圆锥体:轴向。
- 旋转体:轴向。
- `box[]`:面边界,返回一个矩形盒子的对角线上的两个点的坐标(参考绝对坐标系),盒子包含了指定的面并且通常是最小可能的,但是不能保证。
- `radius`:返回面的主要半径。对于圆锥体,半径是在轴上的点[3]处取的。对于环体,半径是在主轴上取的。
- `rad_data`:返回面的次要半径。只有环体或圆锥体具有 rad_data 作为次要半径。对于圆锥体,rad_data 是半角的一半,对于环体,rad_data 是在副轴上取的。
- `norm_dir`:返回面的法线方向。+1 表示面法线与曲面法线(U- 和 V- 导数向量的叉积)相同,-1 表示相反。
函数返回值:
- `0` 表示成功。
- 非 `0` 值表示失败。
使用示例:
```c
#include <uf_modl.h>
#include <stdio.h>
int main()
{
tag_t face;
int type;
double point[3], dir[3], box[6], radius, rad_data;
int norm_dir;
// 获取一个面的 ID
// ...
int ret = UF_MODL_ask_face_data(face, &type, point, dir, box, &radius, &rad_data, &norm_dir);
if (ret != 0)
{
printf("查询面数据失败!\n");
return 1;
}
printf("面类型:%d\n", type);
printf("点坐标:(%lf, %lf, %lf)\n", point[0], point[1], point[2]);
printf("方向向量:(%lf, %lf, %lf)\n", dir[0], dir[1], dir[2]);
printf("盒子坐标:(%lf, %lf, %lf), (%lf, %lf, %lf)\n", box[0], box[1], box[2], box[3], box[4], box[5]);
printf("主要半径:%lf\n", radius);
printf("次要半径:%lf\n", rad_data);
printf("法线方向:%d\n", norm_dir);
return 0;
}
```
该示例中,我们首先获取了一个面对象的 ID `face`,然后调用 `UF_MODL_ask_face_data` 函数查询该面的数据。函数返回成功后,我们打印出面的类型、点坐标、方向向量、盒子坐标、主要半径、次要半径和法线方向。
cairo自定义surface
Cairo是一个功能强大的2D图形库,它支持多种绘图表面(surface)。其中,通过自定义surface,我们可以实现自己的绘图目的。
在Cairo中,Surface是一个表示要绘制的目标的抽象概念。Surface可以是一个窗口、一个图片文件、一个PDF文件等等。要创建一个自定义的surface对象,你需要定义一个Cairo_surface_t结构体,该结构体包含了一些函数指针,用于绑定你的自定义surface对象与Cairo库中的相关函数。
下面是一些示例代码,用于创建一个自定义的surface对象:
```
#include <cairo.h>
typedef struct _MySurface {
cairo_surface_t base;
// Define your own properties here
} MySurface;
static cairo_status_t my_surface_finish(cairo_surface_t *surface) {
// Define your own cleanup code here
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t my_surface_flush(cairo_surface_t *surface) {
// Define your own flush code here
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t my_surface_write_to_png(cairo_surface_t *surface, const char *filename) {
// Define your own code to write to PNG file here
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *my_surface_create_similar(cairo_surface_t *surface, cairo_content_t content, int width, int height) {
// Define your own code to create a similar surface here
return NULL;
}
static cairo_surface_t *my_surface_create_similar_image(cairo_surface_t *surface, cairo_format_t format, int width, int height) {
// Define your own code to create a similar image surface here
return NULL;
}
static cairo_surface_t *my_surface_create_for_rectangle(cairo_surface_t *surface, double x, double y, double width, double height) {
// Define your own code to create a surface for a rectangle here
return NULL;
}
static cairo_surface_t *my_surface_create_observer(cairo_surface_t *surface, cairo_surface_observer_mode_t mode) {
// Define your own code to create an observer surface here
return NULL;
}
static cairo_int_status_t my_surface_acquire_source_image(cairo_surface_t *surface, cairo_image_surface_t **image_out, void **extra_data_out) {
// Define your own code to acquire a source image here
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static void my_surface_release_source_image(cairo_surface_t *surface, cairo_image_surface_t *image, void *extra_data) {
// Define your own code to release the source image here
}
static cairo_int_status_t my_surface_acquire_dest_image(cairo_surface_t *surface, cairo_rectangle_t *interest_rect, cairo_image_surface_t **image_out, cairo_rectangle_t *image_rect_out, void **extra_data_out) {
// Define your own code to acquire a destination image here
return CAIRO_INT_STATUS_UNSUPPORTED;
}
static void my_surface_release_dest_image(cairo_surface_t *surface, cairo_rectangle_t *interest_rect, cairo_image_surface_t *image, cairo_rectangle_t *image_rect, void *extra_data) {
// Define your own code to release the destination image here
}
static cairo_bool_t my_surface_get_extents(cairo_surface_t *surface, cairo_rectangle_t *rectangle) {
// Define your own code to get the extents of the surface here
return FALSE;
}
static cairo_surface_t *my_surface_map_to_image(cairo_surface_t *surface, cairo_rectangle_t *extents) {
// Define your own code to map the surface to an image here
return NULL;
}
static void my_surface_unmap_image(cairo_surface_t *surface, cairo_surface_t *image) {
// Define your own code to unmap the image here
}
static cairo_surface_t *my_surface_map_to_image_surface(cairo_surface_t *surface, cairo_rectangle_t *extents, cairo_format_t format, void **data_out, int *stride_out) {
// Define your own code to map the surface to an image surface here
return NULL;
}
static void my_surface_unmap_image_surface(cairo_surface_t *surface, cairo_surface_t *image_surface, void *data) {
// Define your own code to unmap the image surface here
}
static cairo_status_t my_surface_snapshot(cairo_surface_t *surface, cairo_surface_t **snapshot_out) {
// Define your own code to snapshot the surface here
return CAIRO_STATUS_SUCCESS;
}
static cairo_surface_t *my_surface_copy_page(cairo_surface_t *surface) {
// Define your own code to copy a page of the surface here
return NULL;
}
static cairo_status_t my_surface_show_page(cairo_surface_t *surface) {
// Define your own code to show a page of the surface here
return CAIRO_STATUS_SUCCESS;
}
static cairo_bool_t my_surface_has_show_text_glyphs(cairo_surface_t *surface) {
// Define your own code to determine if the surface supports show_text_glyphs here
return FALSE;
}
static cairo_status_t my_surface_show_text_glyphs(cairo_surface_t *surface, const char *utf8, int utf8_len, const cairo_glyph_t *glyphs, int num_glyphs, const cairo_text_cluster_t *clusters, int num_clusters, const cairo_text_cluster_flags_t *cluster_flags) {
// Define your own code to support show_text_glyphs here
return CAIRO_STATUS_SUCCESS;
}
static cairo_bool_t my_surface_supports_mime_type(cairo_surface_t *surface, const char *mime_type) {
// Define your own code to determine if the surface supports a MIME type here
return FALSE;
}
static cairo_status_t my_surface_set_mime_data(cairo_surface_t *surface, const char *mime_type, const unsigned char *data, unsigned long length, cairo_destroy_func_t destroy, void *closure) {
// Define your own code to set MIME data here
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t my_surface_get_font_options(cairo_surface_t *surface, cairo_font_options_t *options) {
// Define your own code to get font options here
return CAIRO_STATUS_SUCCESS;
}
static cairo_status_t my_surface_flush_image(cairo_surface_t *surface, cairo_surface_t *image_surface, cairo_rectangle_t *extents) {
// Define your own code to flush an image here
return CAIRO_STATUS_SUCCESS;
}
static const cairo_surface_backend_t my_surface_backend = {
CAIRO_SURFACE_TYPE_CUSTOM,
my_surface_finish,
my_surface_create_similar,
my_surface_map_to_image,
my_surface_unmap_image,
my_surface_acquire_source_image,
my_surface_release_source_image,
my_surface_acquire_dest_image,
my_surface_release_dest_image,
my_surface_clone_similar,
my_surface_composite,
my_surface_fill_rectangles,
my_surface_fill_region,
my_surface_set_device_offset,
my_surface_get_device_offset,
my_surface_set_fallback_resolution,
my_surface_get_fallback_resolution,
my_surface_copy_page,
my_surface_show_page,
my_surface_get_extents,
my_surface_has_show_text_glyphs,
my_surface_show_text_glyphs,
my_surface_set_mime_data,
my_surface_supports_mime_type,
my_surface_snapshot,
my_surface_copy_page,
my_surface_show_page,
my_surface_get_font_options,
my_surface_flush,
my_surface_flush_image,
my_surface_create_observer,
my_surface_create_similar_image,
my_surface_map_to_image_surface,
my_surface_unmap_image_surface
};
cairo_surface_t *my_surface_create() {
MySurface *surface = malloc(sizeof(MySurface));
surface->base.backend = &my_surface_backend;
// Initialize your own properties here
return &surface->base;
}
```
在上面的代码中,我们定义了一个MySurface结构体,它是cairo_surface_t的子类。我们还定义了一些函数,这些函数将用于绑定我们的自定义surface对象与Cairo库中的相关函数。
最后,我们定义了一个my_surface_create函数,该函数将创建并返回我们的自定义surface对象。
要使用自定义surface,只需将其传递给cairo_create函数即可:
```
cairo_surface_t *surface = my_surface_create();
cairo_t *cr = cairo_create(surface);
```
现在,我们已经成功地创建了一个自定义的Cairo绘图表面(surface),并且可以使用它来进行绘制操作。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)